ZQuest Classic Coverage Report


Directory: src/
File: src/zc/zc_sys.cpp
Date: 2025-01-13 08:29:44
Exec Total Coverage
Lines: 1951 4485 43.5%
Functions: 136 332 41.0%
Branches: 1314 3734 35.2%

Line Branch Exec Source
1 #include "zc/zc_sys.h"
2
3 #include "allegro/gfx.h"
4 #include "allegro/gui.h"
5 #include "allegro5/joystick.h"
6 #include "base/files.h"
7 #include "base/render.h"
8 #include "zalleg/zalleg.h"
9 #include "base/qrs.h"
10 #include "base/dmap.h"
11 #include <functional>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <cstring>
15 #include <math.h>
16 #include <map>
17 #include <filesystem>
18 #include <ctype.h>
19 #include <sstream>
20 #include "base/version.h"
21 #include "base/zc_alleg.h"
22 #include "gamedata.h"
23 #include "zc/replay_upload.h"
24 #include "zc/zc_init.h"
25 #include "init.h"
26 #include "zc/replay.h"
27 #include "zc/cheats.h"
28 #include "zc/render.h"
29 #include "base/zc_math.h"
30 #include "base/zapp.h"
31 #include "dialog/cheatkeys.h"
32 #include "metadata/metadata.h"
33 #include "zc/zelda.h"
34 #include "zc/saves.h"
35 #include "tiles.h"
36 #include "base/colors.h"
37 #include "pal.h"
38 #include "base/zsys.h"
39 #include "base/qst.h"
40 #include "zc/zc_sys.h"
41 #include "play_midi.h"
42 #include "gui/jwin_a5.h"
43 #include "base/jwinfsel.h"
44 #include "base/gui.h"
45 #include "midi.h"
46 #include "subscr.h"
47 #include "zc/maps.h"
48 #include "sprite.h"
49 #include "zc/guys.h"
50 #include "zc/hero.h"
51 #include "zc/title.h"
52 #include "particles.h"
53 #include "sound/zcmusic.h"
54 #include "zconsole.h"
55 #include "zc/ffscript.h"
56 #include "dialog/info.h"
57 #include "dialog/alert.h"
58 #include "zc/combos.h"
59 #include "zc/jit.h"
60 #include "zc/zc_subscr.h"
61 #include <fmt/format.h>
62 #include "zconsole/ConsoleLogger.h"
63 #include "zinfo.h"
64 #include "base/misctypes.h"
65 #include "music_playback.h"
66 #include <base/new_menu.h>
67 #include <base/files.h>
68
69 #ifdef __EMSCRIPTEN__
70 #include "base/emscripten_utils.h"
71 #endif
72
73 using namespace std::chrono_literals;
74
75 extern bool Playing;
76 int32_t sfx_voice[WAV_COUNT];
77 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
78 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
79
80 static ALLEGRO_JOYSTICK* gamepad_dlg_cur_joystick;
81 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
82
83 extern byte monochrome_console;
84
85 extern HeroClass Hero;
86 extern zcmodule moduledata;
87 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
88 extern particle_list particles;
89 extern int32_t loadlast;
90 extern char *sfx_string[WAV_COUNT];
91 byte use_dwm_flush;
92 byte use_save_indicator;
93 int32_t paused_midi_pos = 0;
94 byte midi_suspended = 0;
95 byte zc_192b163_warp_compatibility;
96 char modulepath[2048];
97 bool epilepsyFlashReduction;
98 signed char pause_in_background_menu_init = 0;
99 byte pause_in_background = 0;
100 bool is_sys_pal = false;
101 static bool load_control_called_this_frame;
102 extern PALETTE* hw_palette;
103 extern bool update_hw_pal;
104 extern const char* dmaplist(int32_t index, int32_t* list_size);
105 int32_t getnumber(const char *prompt,int32_t initialval);
106
107 extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
108 extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
109
110 static const char *qst_module_name = "current_module";
111 #ifdef ALLEGRO_LINUX
112 static const char *samplepath = "samplesoundset/patches.dat";
113 #endif
114 char qst_files_path[2048];
115
116 extern TopMenu the_player_menu;
117 #ifdef _MSC_VER
118 #define getcwd _getcwd
119 #endif
120
121 bool rF11();
122 bool rI();
123 bool rQ();
124 bool zc_key_pressed();
125
126 #ifdef _WIN32
127
128 // This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
129 extern "C"
130 {
131 typedef HRESULT(WINAPI *t_DwmFlush)();
132 typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
133 }
134
135 void do_DwmFlush()
136 {
137 static HMODULE shell = LoadLibrary("dwmapi.dll");
138
139 if(!shell)
140 return;
141
142 static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
143 static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
144
145 BOOL enabled;
146 isEnabled(&enabled);
147
148 if(isEnabled)
149 flush();
150 }
151
152 #endif // _WIN32
153
154 246 void zc_exit(int code)
155 {
156 extern CConsoleLoggerEx zscript_coloured_console;
157
158 246 set_is_exiting();
159
160
1/2
✓ Branch 0 taken 246 times.
✗ Branch 1 not taken.
246 if (replay_get_mode() == ReplayMode::Record) replay_save();
161 246 replay_stop();
162 246 music_stop();
163 246 kill_sfx();
164
165
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 240 times.
246 if (get_qr(qr_OLD_SCRIPT_VOLUME))
166 {
167 //restore user volume settings
168
2/2
✓ Branch 0 taken 239 times.
✓ Branch 1 taken 1 times.
240 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
169 {
170 1 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
171 1 }
172
2/2
✓ Branch 0 taken 239 times.
✓ Branch 1 taken 1 times.
240 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
173 {
174 1 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
175 1 }
176
2/2
✓ Branch 0 taken 239 times.
✓ Branch 1 taken 1 times.
240 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
177 {
178 1 emusic_volume = (int32_t)FFCore.usr_music_volume;
179 1 }
180
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
181 {
182 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
183 }
184 240 }
185
1/2
✓ Branch 0 taken 246 times.
✗ Branch 1 not taken.
246 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
186 {
187 pan_style = (int32_t)FFCore.usr_panstyle;
188 }
189 246 save_game_configs();
190
191 246 zscript_coloured_console.kill();
192 246 jit_shutdown();
193 246 quit_game();
194
195 246 Z_message("ZQuest Classic web site: https://zquestclassic.com\n");
196 246 Z_message("ZQuest Classic old wiki: https://web.archive.org/web/20210910193102/https://zeldaclassic.com/wiki\n");
197 246 Z_message("ZQuest Classic new wiki: https://github.com/ZQuestClassic/ZQuestClassic/wiki\n");
198
199 246 allegro_exit();
200 246 exit(code);
201 }
202
203 92829 bool flash_reduction_enabled(bool check_qr)
204 {
205
4/4
✓ Branch 0 taken 88404 times.
✓ Branch 1 taken 4425 times.
✓ Branch 2 taken 87576 times.
✓ Branch 3 taken 92001 times.
92829 return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
206 }
207
208 // Dialogue largening
209 void large_dialog(DIALOG *d)
210 {
211 large_dialog(d, 1.5);
212 }
213
214 void large_dialog(DIALOG *d, float RESIZE_AMT)
215 {
216 if(!d[0].d1)
217 {
218 d[0].d1 = 1;
219 int32_t oldwidth = d[0].w;
220 int32_t oldheight = d[0].h;
221 int32_t oldx = d[0].x;
222 int32_t oldy = d[0].y;
223 d[0].x -= int32_t(d[0].w/RESIZE_AMT);
224 d[0].y -= int32_t(d[0].h/RESIZE_AMT);
225 d[0].w = int32_t(d[0].w*RESIZE_AMT);
226 d[0].h = int32_t(d[0].h*RESIZE_AMT);
227
228 for(int32_t i=1; d[i].proc !=NULL; i++)
229 {
230 // Place elements horizontally
231 double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
232 d[i].x = int32_t(d[0].x + (xpc*d[0].w));
233
234 if(d[i].proc != d_stringloader)
235 {
236 if(d[i].proc==d_bitmap_proc)
237 {
238 d[i].w *= 2;
239 }
240 else d[i].w = int32_t(d[i].w*RESIZE_AMT);
241 }
242
243 // Place elements vertically
244 double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
245 d[i].y = int32_t(d[0].y + (ypc*d[0].h));
246
247 // Vertically resize elements
248 if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
249 {
250 d[i].h = int32_t((double)d[i].h*1.5);
251 }
252 else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
253 {
254 d[i].y += int32_t((double)d[i].h*0.25);
255 d[i].h = int32_t((double)d[i].h*1.25);
256 }
257 else if(d[i].proc==d_bitmap_proc)
258 {
259 d[i].h *= 2;
260 }
261 else d[i].h = int32_t(d[i].h*RESIZE_AMT);
262
263 // Fix frames
264 if(d[i].proc == jwin_frame_proc)
265 {
266 d[i].x++;
267 d[i].y++;
268 d[i].w-=4;
269 d[i].h-=4;
270 }
271 }
272 }
273
274 for(int32_t i=1; d[i].proc!=NULL; i++)
275 {
276 if(d[i].proc==jwin_slider_proc)
277 continue;
278
279 // Bigger font
280 bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
281
282 if(!d[i].dp2 && bigfontproc)
283 {
284 d[i].dp2 = get_zc_font(font_lfont_l);
285 }
286 else if(!bigfontproc)
287 {
288 ((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
289 }
290
291 // Make checkboxes work
292 if(d[i].proc == jwin_check_proc)
293 d[i].proc = jwin_checkfont_proc;
294 else if(d[i].proc == jwin_radio_proc)
295 d[i].proc = jwin_radiofont_proc;
296 }
297
298 jwin_center_dialog(d);
299 }
300
301 static char cfg_sect[] = "zeldadx"; //We need to rename this.
302 static char ctrl_sect[] = "Controls";
303 static char sfx_sect[] = "Volume";
304
305 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
306 {
307 return D_O_K;
308 }
309
310 bool is_reserved_key(int c)
311 {
312 switch(c)
313 {
314 case KEY_ESC:
315 return true;
316 }
317 return false;
318 }
319 bool is_reserved_keycombo(int c, int modflag)
320 {
321 if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
322 return true;
323 return false;
324 }
325 bool checkcheat(Cheat cheat)
326 {
327 if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
328 return true; //Main key pressed
329 if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
330 return true; //Alt key pressed
331 return false;
332 }
333 246 void load_default_cheatkeys()
334 {
335 246 memset(cheatkeys, 0, sizeof(cheatkeys));
336 246 cheatkeys[Cheat::Life][0] = KEY_H;
337 246 cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
338 246 cheatkeys[Cheat::Magic][0] = KEY_M;
339 246 cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
340 246 cheatkeys[Cheat::Rupies][0] = KEY_R;
341 246 cheatkeys[Cheat::Bombs][0] = KEY_B;
342 246 cheatkeys[Cheat::Arrows][0] = KEY_A;
343 246 cheatkeys[Cheat::Clock][0] = KEY_I;
344 246 cheatkeys[Cheat::Walls][0] = KEY_F11;
345 246 cheatkeys[Cheat::Fast][0] = KEY_Q;
346 246 cheatkeys[Cheat::Light][0] = KEY_L;
347 246 cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
348 246 cheatkeys[Cheat::Kill][0] = KEY_K;
349 246 cheatkeys[Cheat::GoTo][0] = KEY_G;
350 246 cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
351 246 cheatkeys[Cheat::ShowL0][0] = KEY_0;
352 246 cheatkeys[Cheat::ShowL1][0] = KEY_1;
353 246 cheatkeys[Cheat::ShowL2][0] = KEY_2;
354 246 cheatkeys[Cheat::ShowL3][0] = KEY_3;
355 246 cheatkeys[Cheat::ShowL4][0] = KEY_4;
356 246 cheatkeys[Cheat::ShowL5][0] = KEY_5;
357 246 cheatkeys[Cheat::ShowL6][0] = KEY_6;
358 246 cheatkeys[Cheat::ShowFFC][0] = KEY_7;
359 246 cheatkeys[Cheat::ShowSprites][0] = KEY_8;
360 246 cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
361 246 cheatkeys[Cheat::ShowEffects][0] = KEY_E;
362 246 cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
363 246 cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
364 246 cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
365 246 cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
366 246 }
367
368 static bool loaded_game_configs;
369
370 246 void load_game_configs()
371 {
372 246 loaded_game_configs = true;
373 246 strcpy(moduledata.module_name,zc_get_config("ZCMODULE",qst_module_name,"modules/classic.zmod"));
374 246 joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
375 246 js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
376 246 js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
377 246 js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
378 246 js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
379 246 js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
380 246 js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
381 246 js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
382 246 js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
383 246 js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
384 246 js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
385 246 js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
386 246 js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
387 246 analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
388
389 //cheat modifier keya
390 246 cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
391 246 cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
392 246 cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
393 246 cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
394
395 //cheat keys
396 246 load_default_cheatkeys();
397 char buf[256];
398
2/2
✓ Branch 0 taken 246 times.
✓ Branch 1 taken 8856 times.
9102 for(size_t q = 1; q < Cheat::Last; ++q)
399 {
400
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!bindable_cheat((Cheat)q)) continue;
401 8856 std::string cheatname = cheat_to_string((Cheat)q);
402
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 util::lowerstr(cheatname);
403 8856 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
404
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
405 8856 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
406
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
407 8856 }
408
409
1/2
✓ Branch 0 taken 246 times.
✗ Branch 1 not taken.
246 if((uint32_t)joystick_index >= MAX_JOYSTICKS)
410 joystick_index = 0;
411
412 246 Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
413 246 Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
414 246 Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
415 246 Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
416 246 Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
417 246 Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
418 246 Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
419 246 Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
420 246 Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
421 246 Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
422
423 246 DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
424 246 DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
425 246 DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
426 246 DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
427
428 246 Abtn = zc_get_config(ctrl_sect,"btn_a",2);
429 246 Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
430 246 Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
431 246 Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
432 246 Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
433 246 Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
434 246 Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
435 246 Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
436 246 Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
437 246 Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
438 246 Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
439
440 246 DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
441 246 DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
442 246 DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
443 246 DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
444
445 246 epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
446
447 246 midi_volume = zc_get_config(sfx_sect,"midi",255);
448 246 sfx_volume = zc_get_config(sfx_sect,"sfx",255);
449 246 emusic_volume = zc_get_config(sfx_sect,"emusic",255);
450 246 pan_style = zc_get_config(sfx_sect,"pan",1);
451 246 volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
452 246 zc_vsync = zc_get_config(cfg_sect,"vsync",0);
453 246 Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
454 246 Maxfps = zc_get_config(cfg_sect,"maxfps",0);
455 246 TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
456 246 SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
457 246 SnapshotScale = zc_get_config(cfg_sect,"snapshot_scale",2);
458 246 NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
459 #ifdef __EMSCRIPTEN__
460 if (em_is_mobile()) NameEntryMode = 2;
461 #endif
462 246 ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
463 246 ShowGameTime = zc_get_config(cfg_sect,"showtime",0);
464 246 NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
465 246 ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
466 246 abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
467 246 pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
468
469 246 window_width = resx = zc_get_config(cfg_sect,"window_width",-1);
470 246 window_height = resy = zc_get_config(cfg_sect,"window_height",-1);
471 246 SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
472 246 DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
473 246 SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
474 246 scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
475 246 stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
476
477 246 loadlast = zc_get_config(cfg_sect,"load_last",0);
478
479 246 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
480
481 246 info_opacity = zc_get_config("zc","debug_info_opacity",255);
482 #ifdef _WIN32
483 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
484 //use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
485 use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
486
487 // This one's for Aero
488 use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
489
490 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
491 #else //UNIX
492 246 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
493 246 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
494 #endif
495 246 clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
496 246 clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
497
498 246 strcpy(qstdir,zc_get_config(cfg_sect,"quest_dir","quests"));
499 246 strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
500 246 ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
501 246 ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
502 246 ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
503 246 ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
504 246 heart_beep = zc_get_config(cfg_sect,"heart_beep",0)!=0;
505 //gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
506 246 sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1); // TODO: sfxdat is always set to 1 for titlescreen... and 0 in readsfx... so this cfg is pointless, remove?
507 246 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
508 246 use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
509 246 zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
510 246 SkipTitle = zc_get_config(cfg_sect,"skip_title",0);
511 246 }
512
513 void save_control_configs(bool kb)
514 {
515 if(kb)
516 {
517 zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
518 zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
519 zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
520 zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
521
522 if (!replay_is_replaying())
523 {
524 zc_set_config(ctrl_sect,"key_a",Akey);
525 zc_set_config(ctrl_sect,"key_b",Bkey);
526 zc_set_config(ctrl_sect,"key_s",Skey);
527 zc_set_config(ctrl_sect,"key_l",Lkey);
528 zc_set_config(ctrl_sect,"key_r",Rkey);
529 zc_set_config(ctrl_sect,"key_p",Pkey);
530 zc_set_config(ctrl_sect,"key_ex1",Exkey1);
531 zc_set_config(ctrl_sect,"key_ex2",Exkey2);
532 zc_set_config(ctrl_sect,"key_ex3",Exkey3);
533 zc_set_config(ctrl_sect,"key_ex4",Exkey4);
534 zc_set_config(ctrl_sect,"key_up", DUkey);
535 zc_set_config(ctrl_sect,"key_down", DDkey);
536 zc_set_config(ctrl_sect,"key_left", DLkey);
537 zc_set_config(ctrl_sect,"key_right",DRkey);
538 }
539 }
540 else
541 {
542 zc_set_config(ctrl_sect,"joystick_index",joystick_index);
543 zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
544 zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
545 zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
546 zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
547 zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
548 zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
549 zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
550 zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
551 zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
552 zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
553 zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
554 zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
555 zc_set_config(ctrl_sect,"analog_movement",analog_movement);
556
557 zc_set_config(ctrl_sect,"btn_a",Abtn);
558 zc_set_config(ctrl_sect,"btn_b",Bbtn);
559 zc_set_config(ctrl_sect,"btn_s",Sbtn);
560 zc_set_config(ctrl_sect,"btn_m",Mbtn);
561 zc_set_config(ctrl_sect,"btn_l",Lbtn);
562 zc_set_config(ctrl_sect,"btn_r",Rbtn);
563 zc_set_config(ctrl_sect,"btn_p",Pbtn);
564 zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
565 zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
566 zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
567 zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
568
569 zc_set_config(ctrl_sect,"btn_up",DUbtn);
570 zc_set_config(ctrl_sect,"btn_down",DDbtn);
571 zc_set_config(ctrl_sect,"btn_left",DLbtn);
572 zc_set_config(ctrl_sect,"btn_right",DRbtn);
573 }
574 }
575
576 void save_cheatkeys()
577 {
578 char buf[256];
579 for(size_t q = 1; q < Cheat::Last; ++q)
580 {
581 if(!bindable_cheat((Cheat)q)) continue;
582 std::string cheatname = cheat_to_string((Cheat)q);
583 util::lowerstr(cheatname);
584 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
585 zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
586 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
587 if(cheatkeys[q][1])
588 zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
589 else zc_set_config(ctrl_sect,buf,(char*)nullptr);
590 }
591 }
592
593 246 void save_game_configs()
594 {
595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 246 times.
246 if (!loaded_game_configs) return;
596
597 246 packfile_password("");
598
599 246 zc_set_config("ZCMODULE",qst_module_name,moduledata.module_name);
600
601
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 246 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
246 if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
602 {
603 int o_window_x, o_window_y;
604 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
605 zc_set_config(cfg_sect,"window_x",o_window_x);
606 zc_set_config(cfg_sect,"window_y",o_window_y);
607 }
608
609
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 246 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
246 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
610 {
611 window_width = al_get_display_width(all_get_display());
612 window_height = al_get_display_height(all_get_display());
613 zc_set_config(cfg_sect,"window_width",window_width);
614 zc_set_config(cfg_sect,"window_height",window_height);
615 }
616
617 246 zc_set_config(cfg_sect,"load_last",loadlast);
618 246 zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
619
620 246 flush_config_file();
621 #ifdef __EMSCRIPTEN__
622 em_sync_fs();
623 #endif
624 246 }
625
626 //----------------------------------------------------------------
627
628 // Timers
629
630 43237 void fps_callback()
631 {
632 43237 lastfps=framecnt;
633 43237 framecnt=0;
634 43237 }
635
636 END_OF_FUNCTION(fps_callback)
637
638 246 int32_t Z_init_timers()
639 {
640 static bool didit = false;
641 const static char *err_str = "Couldn't allocate timer";
642 246 err_str = err_str; //Unused variable warning
643
644
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 246 times.
246 if(didit)
645 return 1;
646
647 246 didit = true;
648
649 LOCK_VARIABLE(lastfps);
650 LOCK_VARIABLE(framecnt);
651 LOCK_FUNCTION(fps_callback);
652
653
1/2
✓ Branch 0 taken 246 times.
✗ Branch 1 not taken.
246 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
654 return 0;
655
656 246 return 1;
657 246 }
658
659 246 void Z_remove_timers()
660 {
661 246 remove_int(fps_callback);
662 246 }
663
664 //----------------------------------------------------------------
665
666 void go()
667 {
668 blit(screen,tmp_scr,scrx,scry,0,0,screen->w,screen->h);
669 }
670
671 void comeback()
672 {
673 blit(tmp_scr,screen,0,0,scrx,scry,screen->w,screen->h);
674 }
675
676 void dump_pal(BITMAP *dest)
677 {
678 for(int32_t i=0; i<256; i++)
679 rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
680 }
681
682 //----------------------------------------------------------------
683
684 int game_mouse_index = ZCM_BLANK;
685 static bool system_mouse = false;
686 110 bool sys_mouse()
687 {
688 110 system_mouse = true;
689 110 return MouseSprite::set(ZCM_NORMAL);
690 }
691 1481 bool game_mouse()
692 {
693 1481 system_mouse = false;
694 1481 return MouseSprite::set(game_mouse_index);
695 }
696 void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
697 {
698 if(!bmp)
699 return;
700 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
701 int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
702 if(bmp->w == scaledw && bmp->h == scaledh)
703 user_scale = false;
704 if(user_scale || sys_recolor)
705 {
706 if(!user_scale) scale = 1;
707 BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
708 if(user_scale)
709 stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
710 else
711 blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
712 if(sys_recolor)
713 recolor_mouse(tmpbmp);
714 MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
715 destroy_bitmap(tmpbmp);
716 }
717 else
718 {
719 MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
720 }
721 }
722
723 //Handles converting the mouse sprite from the .dat file
724 void recolor_mouse(BITMAP* bmp)
725 {
726 for(int32_t x = 0; x < bmp->w; ++x)
727 {
728 for(int32_t y = 0; y < bmp->h; ++y)
729 {
730 int32_t color = getpixel(bmp, x, y);
731 switch(color)
732 {
733 case dvc(1):
734 color = jwin_pal[jcCURSORMISC];
735 break;
736 case dvc(2):
737 color = jwin_pal[jcCURSOROUTLINE];
738 break;
739 case dvc(3):
740 color = jwin_pal[jcCURSORLIGHT];
741 break;
742 case dvc(5):
743 color = jwin_pal[jcCURSORDARK];
744 break;
745 default:
746 continue;
747 }
748 putpixel(bmp, x, y, color);
749 }
750 }
751 }
752 void load_mouse()
753 {
754 PALETTE pal;
755 BITMAP* cursor_bitmap = load_bitmap("assets/cursor.bmp", pal);
756 if (!cursor_bitmap)
757 Z_error_fatal("Missing required file %s\n", "assets/cursor.bmp");
758
759 enter_sys_pal();
760 MouseSprite::set(-1);
761 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
762 int32_t sz = 16*scale;
763 for(int32_t j = 0; j < 1; ++j)
764 {
765 BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
766 if(zcmouse[j])
767 destroy_bitmap(zcmouse[j]);
768 zcmouse[j] = create_bitmap_ex(8,sz,sz);
769 clear_bitmap(zcmouse[j]);
770 clear_bitmap(tmpbmp);
771 blit(cursor_bitmap,tmpbmp,1,j*17+1,0,0,16,16);
772 recolor_mouse(tmpbmp);
773 if(sz!=16)
774 stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
775 else
776 blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
777 destroy_bitmap(tmpbmp);
778 }
779 if(!hw_palette) hw_palette = &RAMpal;
780 zc_set_palette(*hw_palette);
781
782 BITMAP* blankmouse = create_bitmap_ex(8,16,16);
783 clear_bitmap(blankmouse);
784
785 MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
786 MouseSprite::assign(ZCM_BLANK, blankmouse);
787 //Don't assign ZCM_CUSTOM. That'll be handled by scripts.
788
789 //Reload the mouse
790 if(system_mouse)
791 sys_mouse();
792 else game_mouse();
793
794 destroy_bitmap(blankmouse);
795 destroy_bitmap(cursor_bitmap);
796 exit_sys_pal();
797 }
798
799 // sets the video mode and initializes the palette and mouse sprite
800 246 bool game_vid_mode(int32_t mode,int32_t wait)
801 {
802
1/2
✓ Branch 0 taken 246 times.
✗ Branch 1 not taken.
246 if (is_headless())
803 246 return true;
804
805 extern int zq_screen_w, zq_screen_h;
806 if(set_gfx_mode(mode,resx,resy,zq_screen_w,zq_screen_h)!=0)
807 {
808 return false;
809 }
810
811 scrx = (resx-320)>>1;
812 scry = (resy-240)>>1;
813 for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
814 zcmouse[q] = NULL;
815 load_mouse();
816
817 for(int32_t i=240; i<256; i++)
818 RAMpal[i]=pal_gui[i];
819
820 zc_set_palette(RAMpal);
821 clear_to_color(screen,BLACK);
822
823 rest(wait);
824 return true;
825 246 }
826
827 254 void null_quest()
828 {
829
1/2
✓ Branch 0 taken 254 times.
✗ Branch 1 not taken.
254 std::string title_assets_path = "modules/classic/title_gfx.dat";
830
2/4
✓ Branch 0 taken 254 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 254 times.
254 if (get_last_loaded_qstpath() == title_assets_path)
831 return;
832
833 byte skip_flags[4];
834
2/2
✓ Branch 0 taken 254 times.
✓ Branch 1 taken 6604 times.
6858 for (int i = 0; i < skip_max; i++)
835
1/2
✓ Branch 0 taken 6604 times.
✗ Branch 1 not taken.
6604 set_bit(skip_flags, i, 1);
836
1/2
✓ Branch 0 taken 254 times.
✗ Branch 1 not taken.
254 set_bit(skip_flags, skip_tiles, 0);
837
1/2
✓ Branch 0 taken 254 times.
✗ Branch 1 not taken.
254 set_bit(skip_flags, skip_csets, 0);
838
1/2
✓ Branch 0 taken 254 times.
✗ Branch 1 not taken.
254 set_bit(skip_flags, skip_misc, 0); // needed for miscsfx (skip this and `tests/replays/demons_inferno/demons_inferno_1_of_2.zplay` fails).
839
1/2
✓ Branch 0 taken 254 times.
✗ Branch 1 not taken.
254 loadquest(title_assets_path.c_str(), &QHeader, &QMisc, tunes+ZC_MIDI_COUNT, false, skip_flags, 0, false);
840 254 sfxdat = 1;
841 // TODO: sfx.dat is ~1.2 MB. Could be better to break that up into individual files and load on demand / not at startup.
842 // TODO: can we cache the tiles/colordata so we don't have to read title_gfx.dat more than once?
843 // colordata is tiny, but tilebuf is huge, so limit that to just what the title screen needs.
844 // Another option: embed this data into the binary (`xxd -i resources/modules/classic/title_gfx.dat > title_gfx.h`)
845
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 254 times.
254 }
846
847 254 void init_NES_mode()
848 {
849 254 null_quest();
850 254 }
851
852 //----------------------------------------------------------------
853
854 qword trianglelines[16]=
855 {
856 0x0000000000000000ULL,
857 0xFD00000000000000ULL,
858 0xFDFD000000000000ULL,
859 0xFDFDFD0000000000ULL,
860 0xFDFDFDFD00000000ULL,
861 0xFDFDFDFDFD000000ULL,
862 0xFDFDFDFDFDFD0000ULL,
863 0xFDFDFDFDFDFDFD00ULL,
864 0xFDFDFDFDFDFDFDFDULL,
865 0x00FDFDFDFDFDFDFDULL,
866 0x0000FDFDFDFDFDFDULL,
867 0x000000FDFDFDFDFDULL,
868 0x00000000FDFDFDFDULL,
869 0x0000000000FDFDFDULL,
870 0x000000000000FDFDULL,
871 0x00000000000000FDULL,
872 };
873
874 word screen_triangles[28][32];
875
876 // the ULL suffixes are to prevent this warning:
877 // warning: integer constant is too large for "int32_t" type
878
879 qword triangles[4][16][8]= //[direction][value][line]
880 {
881 {
882 {
883 0x0000000000000000ULL,
884 0x0000000000000000ULL,
885 0x0000000000000000ULL,
886 0x0000000000000000ULL,
887 0x0000000000000000ULL,
888 0x0000000000000000ULL,
889 0x0000000000000000ULL,
890 0x0000000000000000ULL
891 },
892 {
893 0xFD00000000000000ULL,
894 0x0000000000000000ULL,
895 0x0000000000000000ULL,
896 0x0000000000000000ULL,
897 0x0000000000000000ULL,
898 0x0000000000000000ULL,
899 0x0000000000000000ULL,
900 0x0000000000000000ULL
901 },
902 {
903 0xFDFD000000000000ULL,
904 0xFD00000000000000ULL,
905 0x0000000000000000ULL,
906 0x0000000000000000ULL,
907 0x0000000000000000ULL,
908 0x0000000000000000ULL,
909 0x0000000000000000ULL,
910 0x0000000000000000ULL
911 },
912 {
913 0xFDFDFD0000000000ULL,
914 0xFDFD000000000000ULL,
915 0xFD00000000000000ULL,
916 0x0000000000000000ULL,
917 0x0000000000000000ULL,
918 0x0000000000000000ULL,
919 0x0000000000000000ULL,
920 0x0000000000000000ULL
921 },
922 {
923 0xFDFDFDFD00000000ULL,
924 0xFDFDFD0000000000ULL,
925 0xFDFD000000000000ULL,
926 0xFD00000000000000ULL,
927 0x0000000000000000ULL,
928 0x0000000000000000ULL,
929 0x0000000000000000ULL,
930 0x0000000000000000ULL
931 },
932 {
933 0xFDFDFDFDFD000000ULL,
934 0xFDFDFDFD00000000ULL,
935 0xFDFDFD0000000000ULL,
936 0xFDFD000000000000ULL,
937 0xFD00000000000000ULL,
938 0x0000000000000000ULL,
939 0x0000000000000000ULL,
940 0x0000000000000000ULL
941 },
942 {
943 0xFDFDFDFDFDFD0000ULL,
944 0xFDFDFDFDFD000000ULL,
945 0xFDFDFDFD00000000ULL,
946 0xFDFDFD0000000000ULL,
947 0xFDFD000000000000ULL,
948 0xFD00000000000000ULL,
949 0x0000000000000000ULL,
950 0x0000000000000000ULL
951 },
952 {
953 0xFDFDFDFDFDFDFD00ULL,
954 0xFDFDFDFDFDFD0000ULL,
955 0xFDFDFDFDFD000000ULL,
956 0xFDFDFDFD00000000ULL,
957 0xFDFDFD0000000000ULL,
958 0xFDFD000000000000ULL,
959 0xFD00000000000000ULL,
960 0x0000000000000000ULL
961 },
962 {
963 0xFDFDFDFDFDFDFDFDULL,
964 0xFDFDFDFDFDFDFD00ULL,
965 0xFDFDFDFDFDFD0000ULL,
966 0xFDFDFDFDFD000000ULL,
967 0xFDFDFDFD00000000ULL,
968 0xFDFDFD0000000000ULL,
969 0xFDFD000000000000ULL,
970 0xFD00000000000000ULL
971 },
972 {
973 0xFDFDFDFDFDFDFDFDULL,
974 0xFDFDFDFDFDFDFDFDULL,
975 0xFDFDFDFDFDFDFD00ULL,
976 0xFDFDFDFDFDFD0000ULL,
977 0xFDFDFDFDFD000000ULL,
978 0xFDFDFDFD00000000ULL,
979 0xFDFDFD0000000000ULL,
980 0xFDFD000000000000ULL
981 },
982 {
983 0xFDFDFDFDFDFDFDFDULL,
984 0xFDFDFDFDFDFDFDFDULL,
985 0xFDFDFDFDFDFDFDFDULL,
986 0xFDFDFDFDFDFDFD00ULL,
987 0xFDFDFDFDFDFD0000ULL,
988 0xFDFDFDFDFD000000ULL,
989 0xFDFDFDFD00000000ULL,
990 0xFDFDFD0000000000ULL
991 },
992 {
993 0xFDFDFDFDFDFDFDFDULL,
994 0xFDFDFDFDFDFDFDFDULL,
995 0xFDFDFDFDFDFDFDFDULL,
996 0xFDFDFDFDFDFDFDFDULL,
997 0xFDFDFDFDFDFDFD00ULL,
998 0xFDFDFDFDFDFD0000ULL,
999 0xFDFDFDFDFD000000ULL,
1000 0xFDFDFDFD00000000ULL
1001 },
1002 {
1003 0xFDFDFDFDFDFDFDFDULL,
1004 0xFDFDFDFDFDFDFDFDULL,
1005 0xFDFDFDFDFDFDFDFDULL,
1006 0xFDFDFDFDFDFDFDFDULL,
1007 0xFDFDFDFDFDFDFDFDULL,
1008 0xFDFDFDFDFDFDFD00ULL,
1009 0xFDFDFDFDFDFD0000ULL,
1010 0xFDFDFDFDFD000000ULL
1011 },
1012 {
1013 0xFDFDFDFDFDFDFDFDULL,
1014 0xFDFDFDFDFDFDFDFDULL,
1015 0xFDFDFDFDFDFDFDFDULL,
1016 0xFDFDFDFDFDFDFDFDULL,
1017 0xFDFDFDFDFDFDFDFDULL,
1018 0xFDFDFDFDFDFDFDFDULL,
1019 0xFDFDFDFDFDFDFD00ULL,
1020 0xFDFDFDFDFDFD0000ULL
1021 },
1022 {
1023 0xFDFDFDFDFDFDFDFDULL,
1024 0xFDFDFDFDFDFDFDFDULL,
1025 0xFDFDFDFDFDFDFDFDULL,
1026 0xFDFDFDFDFDFDFDFDULL,
1027 0xFDFDFDFDFDFDFDFDULL,
1028 0xFDFDFDFDFDFDFDFDULL,
1029 0xFDFDFDFDFDFDFDFDULL,
1030 0xFDFDFDFDFDFDFD00ULL
1031 },
1032 {
1033 0xFDFDFDFDFDFDFDFDULL,
1034 0xFDFDFDFDFDFDFDFDULL,
1035 0xFDFDFDFDFDFDFDFDULL,
1036 0xFDFDFDFDFDFDFDFDULL,
1037 0xFDFDFDFDFDFDFDFDULL,
1038 0xFDFDFDFDFDFDFDFDULL,
1039 0xFDFDFDFDFDFDFDFDULL,
1040 0xFDFDFDFDFDFDFDFDULL
1041 }
1042 },
1043 {
1044 {
1045 0x0000000000000000ULL,
1046 0x0000000000000000ULL,
1047 0x0000000000000000ULL,
1048 0x0000000000000000ULL,
1049 0x0000000000000000ULL,
1050 0x0000000000000000ULL,
1051 0x0000000000000000ULL,
1052 0x0000000000000000ULL
1053 },
1054 {
1055 0x00000000000000FDULL,
1056 0x0000000000000000ULL,
1057 0x0000000000000000ULL,
1058 0x0000000000000000ULL,
1059 0x0000000000000000ULL,
1060 0x0000000000000000ULL,
1061 0x0000000000000000ULL,
1062 0x0000000000000000ULL
1063 },
1064 {
1065 0x000000000000FDFDULL,
1066 0x00000000000000FDULL,
1067 0x0000000000000000ULL,
1068 0x0000000000000000ULL,
1069 0x0000000000000000ULL,
1070 0x0000000000000000ULL,
1071 0x0000000000000000ULL,
1072 0x0000000000000000ULL
1073 },
1074 {
1075 0x0000000000FDFDFDULL,
1076 0x000000000000FDFDULL,
1077 0x00000000000000FDULL,
1078 0x0000000000000000ULL,
1079 0x0000000000000000ULL,
1080 0x0000000000000000ULL,
1081 0x0000000000000000ULL,
1082 0x0000000000000000ULL
1083 },
1084 {
1085 0x00000000FDFDFDFDULL,
1086 0x0000000000FDFDFDULL,
1087 0x000000000000FDFDULL,
1088 0x00000000000000FDULL,
1089 0x0000000000000000ULL,
1090 0x0000000000000000ULL,
1091 0x0000000000000000ULL,
1092 0x0000000000000000ULL
1093 },
1094 {
1095 0x000000FDFDFDFDFDULL,
1096 0x00000000FDFDFDFDULL,
1097 0x0000000000FDFDFDULL,
1098 0x000000000000FDFDULL,
1099 0x00000000000000FDULL,
1100 0x0000000000000000ULL,
1101 0x0000000000000000ULL,
1102 0x0000000000000000ULL
1103 },
1104 {
1105 0x0000FDFDFDFDFDFDULL,
1106 0x000000FDFDFDFDFDULL,
1107 0x00000000FDFDFDFDULL,
1108 0x0000000000FDFDFDULL,
1109 0x000000000000FDFDULL,
1110 0x00000000000000FDULL,
1111 0x0000000000000000ULL,
1112 0x0000000000000000ULL
1113 },
1114 {
1115 0x00FDFDFDFDFDFDFDULL,
1116 0x0000FDFDFDFDFDFDULL,
1117 0x000000FDFDFDFDFDULL,
1118 0x00000000FDFDFDFDULL,
1119 0x0000000000FDFDFDULL,
1120 0x000000000000FDFDULL,
1121 0x00000000000000FDULL,
1122 0x0000000000000000ULL
1123 },
1124 {
1125 0xFDFDFDFDFDFDFDFDULL,
1126 0x00FDFDFDFDFDFDFDULL,
1127 0x0000FDFDFDFDFDFDULL,
1128 0x000000FDFDFDFDFDULL,
1129 0x00000000FDFDFDFDULL,
1130 0x0000000000FDFDFDULL,
1131 0x000000000000FDFDULL,
1132 0x00000000000000FDULL
1133 },
1134 {
1135 0xFDFDFDFDFDFDFDFDULL,
1136 0xFDFDFDFDFDFDFDFDULL,
1137 0x00FDFDFDFDFDFDFDULL,
1138 0x0000FDFDFDFDFDFDULL,
1139 0x000000FDFDFDFDFDULL,
1140 0x00000000FDFDFDFDULL,
1141 0x0000000000FDFDFDULL,
1142 0x000000000000FDFDULL
1143 },
1144 {
1145 0xFDFDFDFDFDFDFDFDULL,
1146 0xFDFDFDFDFDFDFDFDULL,
1147 0xFDFDFDFDFDFDFDFDULL,
1148 0x00FDFDFDFDFDFDFDULL,
1149 0x0000FDFDFDFDFDFDULL,
1150 0x000000FDFDFDFDFDULL,
1151 0x00000000FDFDFDFDULL,
1152 0x0000000000FDFDFDULL
1153 },
1154 {
1155 0xFDFDFDFDFDFDFDFDULL,
1156 0xFDFDFDFDFDFDFDFDULL,
1157 0xFDFDFDFDFDFDFDFDULL,
1158 0xFDFDFDFDFDFDFDFDULL,
1159 0x00FDFDFDFDFDFDFDULL,
1160 0x0000FDFDFDFDFDFDULL,
1161 0x000000FDFDFDFDFDULL,
1162 0x00000000FDFDFDFDULL
1163 },
1164 {
1165 0xFDFDFDFDFDFDFDFDULL,
1166 0xFDFDFDFDFDFDFDFDULL,
1167 0xFDFDFDFDFDFDFDFDULL,
1168 0xFDFDFDFDFDFDFDFDULL,
1169 0xFDFDFDFDFDFDFDFDULL,
1170 0x00FDFDFDFDFDFDFDULL,
1171 0x0000FDFDFDFDFDFDULL,
1172 0x000000FDFDFDFDFDULL
1173 },
1174 {
1175 0xFDFDFDFDFDFDFDFDULL,
1176 0xFDFDFDFDFDFDFDFDULL,
1177 0xFDFDFDFDFDFDFDFDULL,
1178 0xFDFDFDFDFDFDFDFDULL,
1179 0xFDFDFDFDFDFDFDFDULL,
1180 0xFDFDFDFDFDFDFDFDULL,
1181 0x00FDFDFDFDFDFDFDULL,
1182 0x0000FDFDFDFDFDFDULL
1183 },
1184 {
1185 0xFDFDFDFDFDFDFDFDULL,
1186 0xFDFDFDFDFDFDFDFDULL,
1187 0xFDFDFDFDFDFDFDFDULL,
1188 0xFDFDFDFDFDFDFDFDULL,
1189 0xFDFDFDFDFDFDFDFDULL,
1190 0xFDFDFDFDFDFDFDFDULL,
1191 0xFDFDFDFDFDFDFDFDULL,
1192 0x00FDFDFDFDFDFDFDULL
1193 },
1194 {
1195 0xFDFDFDFDFDFDFDFDULL,
1196 0xFDFDFDFDFDFDFDFDULL,
1197 0xFDFDFDFDFDFDFDFDULL,
1198 0xFDFDFDFDFDFDFDFDULL,
1199 0xFDFDFDFDFDFDFDFDULL,
1200 0xFDFDFDFDFDFDFDFDULL,
1201 0xFDFDFDFDFDFDFDFDULL,
1202 0xFDFDFDFDFDFDFDFDULL
1203 }
1204 },
1205 {
1206 {
1207 0x0000000000000000ULL,
1208 0x0000000000000000ULL,
1209 0x0000000000000000ULL,
1210 0x0000000000000000ULL,
1211 0x0000000000000000ULL,
1212 0x0000000000000000ULL,
1213 0x0000000000000000ULL,
1214 0x0000000000000000ULL
1215 },
1216 {
1217 0x0000000000000000ULL,
1218 0x0000000000000000ULL,
1219 0x0000000000000000ULL,
1220 0x0000000000000000ULL,
1221 0x0000000000000000ULL,
1222 0x0000000000000000ULL,
1223 0x0000000000000000ULL,
1224 0xFD00000000000000ULL
1225 },
1226 {
1227 0x0000000000000000ULL,
1228 0x0000000000000000ULL,
1229 0x0000000000000000ULL,
1230 0x0000000000000000ULL,
1231 0x0000000000000000ULL,
1232 0x0000000000000000ULL,
1233 0xFD00000000000000ULL,
1234 0xFDFD000000000000ULL
1235 },
1236 {
1237 0x0000000000000000ULL,
1238 0x0000000000000000ULL,
1239 0x0000000000000000ULL,
1240 0x0000000000000000ULL,
1241 0x0000000000000000ULL,
1242 0xFD00000000000000ULL,
1243 0xFDFD000000000000ULL,
1244 0xFDFDFD0000000000ULL
1245 },
1246 {
1247 0x0000000000000000ULL,
1248 0x0000000000000000ULL,
1249 0x0000000000000000ULL,
1250 0x0000000000000000ULL,
1251 0xFD00000000000000ULL,
1252 0xFDFD000000000000ULL,
1253 0xFDFDFD0000000000ULL,
1254 0xFDFDFDFD00000000ULL
1255 },
1256 {
1257 0x0000000000000000ULL,
1258 0x0000000000000000ULL,
1259 0x0000000000000000ULL,
1260 0xFD00000000000000ULL,
1261 0xFDFD000000000000ULL,
1262 0xFDFDFD0000000000ULL,
1263 0xFDFDFDFD00000000ULL,
1264 0xFDFDFDFDFD000000ULL
1265 },
1266 {
1267 0x0000000000000000ULL,
1268 0x0000000000000000ULL,
1269 0xFD00000000000000ULL,
1270 0xFDFD000000000000ULL,
1271 0xFDFDFD0000000000ULL,
1272 0xFDFDFDFD00000000ULL,
1273 0xFDFDFDFDFD000000ULL,
1274 0xFDFDFDFDFDFD0000ULL
1275 },
1276 {
1277 0x0000000000000000ULL,
1278 0xFD00000000000000ULL,
1279 0xFDFD000000000000ULL,
1280 0xFDFDFD0000000000ULL,
1281 0xFDFDFDFD00000000ULL,
1282 0xFDFDFDFDFD000000ULL,
1283 0xFDFDFDFDFDFD0000ULL,
1284 0xFDFDFDFDFDFDFD00ULL
1285 },
1286 {
1287 0xFD00000000000000ULL,
1288 0xFDFD000000000000ULL,
1289 0xFDFDFD0000000000ULL,
1290 0xFDFDFDFD00000000ULL,
1291 0xFDFDFDFDFD000000ULL,
1292 0xFDFDFDFDFDFD0000ULL,
1293 0xFDFDFDFDFDFDFD00ULL,
1294 0xFDFDFDFDFDFDFDFDULL
1295 },
1296 {
1297 0xFDFD000000000000ULL,
1298 0xFDFDFD0000000000ULL,
1299 0xFDFDFDFD00000000ULL,
1300 0xFDFDFDFDFD000000ULL,
1301 0xFDFDFDFDFDFD0000ULL,
1302 0xFDFDFDFDFDFDFD00ULL,
1303 0xFDFDFDFDFDFDFDFDULL,
1304 0xFDFDFDFDFDFDFDFDULL
1305 },
1306 {
1307 0xFDFDFD0000000000ULL,
1308 0xFDFDFDFD00000000ULL,
1309 0xFDFDFDFDFD000000ULL,
1310 0xFDFDFDFDFDFD0000ULL,
1311 0xFDFDFDFDFDFDFD00ULL,
1312 0xFDFDFDFDFDFDFDFDULL,
1313 0xFDFDFDFDFDFDFDFDULL,
1314 0xFDFDFDFDFDFDFDFDULL
1315 },
1316 {
1317 0xFDFDFDFD00000000ULL,
1318 0xFDFDFDFDFD000000ULL,
1319 0xFDFDFDFDFDFD0000ULL,
1320 0xFDFDFDFDFDFDFD00ULL,
1321 0xFDFDFDFDFDFDFDFDULL,
1322 0xFDFDFDFDFDFDFDFDULL,
1323 0xFDFDFDFDFDFDFDFDULL,
1324 0xFDFDFDFDFDFDFDFDULL
1325 },
1326 {
1327 0xFDFDFDFDFD000000ULL,
1328 0xFDFDFDFDFDFD0000ULL,
1329 0xFDFDFDFDFDFDFD00ULL,
1330 0xFDFDFDFDFDFDFDFDULL,
1331 0xFDFDFDFDFDFDFDFDULL,
1332 0xFDFDFDFDFDFDFDFDULL,
1333 0xFDFDFDFDFDFDFDFDULL,
1334 0xFDFDFDFDFDFDFDFDULL
1335 },
1336 {
1337 0xFDFDFDFDFDFD0000ULL,
1338 0xFDFDFDFDFDFDFD00ULL,
1339 0xFDFDFDFDFDFDFDFDULL,
1340 0xFDFDFDFDFDFDFDFDULL,
1341 0xFDFDFDFDFDFDFDFDULL,
1342 0xFDFDFDFDFDFDFDFDULL,
1343 0xFDFDFDFDFDFDFDFDULL,
1344 0xFDFDFDFDFDFDFDFDULL
1345 },
1346 {
1347 0xFDFDFDFDFDFDFD00ULL,
1348 0xFDFDFDFDFDFDFDFDULL,
1349 0xFDFDFDFDFDFDFDFDULL,
1350 0xFDFDFDFDFDFDFDFDULL,
1351 0xFDFDFDFDFDFDFDFDULL,
1352 0xFDFDFDFDFDFDFDFDULL,
1353 0xFDFDFDFDFDFDFDFDULL,
1354 0xFDFDFDFDFDFDFDFDULL
1355 },
1356 {
1357 0xFDFDFDFDFDFDFDFDULL,
1358 0xFDFDFDFDFDFDFDFDULL,
1359 0xFDFDFDFDFDFDFDFDULL,
1360 0xFDFDFDFDFDFDFDFDULL,
1361 0xFDFDFDFDFDFDFDFDULL,
1362 0xFDFDFDFDFDFDFDFDULL,
1363 0xFDFDFDFDFDFDFDFDULL,
1364 0xFDFDFDFDFDFDFDFDULL
1365 }
1366 },
1367 {
1368 {
1369 0x0000000000000000ULL,
1370 0x0000000000000000ULL,
1371 0x0000000000000000ULL,
1372 0x0000000000000000ULL,
1373 0x0000000000000000ULL,
1374 0x0000000000000000ULL,
1375 0x0000000000000000ULL,
1376 0x0000000000000000ULL
1377 },
1378 {
1379 0x0000000000000000ULL,
1380 0x0000000000000000ULL,
1381 0x0000000000000000ULL,
1382 0x0000000000000000ULL,
1383 0x0000000000000000ULL,
1384 0x0000000000000000ULL,
1385 0x0000000000000000ULL,
1386 0x00000000000000FDULL
1387 },
1388 {
1389 0x0000000000000000ULL,
1390 0x0000000000000000ULL,
1391 0x0000000000000000ULL,
1392 0x0000000000000000ULL,
1393 0x0000000000000000ULL,
1394 0x0000000000000000ULL,
1395 0x00000000000000FDULL,
1396 0x000000000000FDFDULL
1397 },
1398 {
1399 0x0000000000000000ULL,
1400 0x0000000000000000ULL,
1401 0x0000000000000000ULL,
1402 0x0000000000000000ULL,
1403 0x0000000000000000ULL,
1404 0x00000000000000FDULL,
1405 0x000000000000FDFDULL,
1406 0x0000000000FDFDFDULL
1407 },
1408 {
1409 0x0000000000000000ULL,
1410 0x0000000000000000ULL,
1411 0x0000000000000000ULL,
1412 0x0000000000000000ULL,
1413 0x00000000000000FDULL,
1414 0x000000000000FDFDULL,
1415 0x0000000000FDFDFDULL,
1416 0x00000000FDFDFDFDULL
1417 },
1418 {
1419 0x0000000000000000ULL,
1420 0x0000000000000000ULL,
1421 0x0000000000000000ULL,
1422 0x00000000000000FDULL,
1423 0x000000000000FDFDULL,
1424 0x0000000000FDFDFDULL,
1425 0x00000000FDFDFDFDULL,
1426 0x000000FDFDFDFDFDULL
1427 },
1428 {
1429 0x0000000000000000ULL,
1430 0x0000000000000000ULL,
1431 0x00000000000000FDULL,
1432 0x000000000000FDFDULL,
1433 0x0000000000FDFDFDULL,
1434 0x00000000FDFDFDFDULL,
1435 0x000000FDFDFDFDFDULL,
1436 0x0000FDFDFDFDFDFDULL
1437 },
1438 {
1439 0x0000000000000000ULL,
1440 0x00000000000000FDULL,
1441 0x000000000000FDFDULL,
1442 0x0000000000FDFDFDULL,
1443 0x00000000FDFDFDFDULL,
1444 0x000000FDFDFDFDFDULL,
1445 0x0000FDFDFDFDFDFDULL,
1446 0x00FDFDFDFDFDFDFDULL
1447 },
1448 {
1449 0x00000000000000FDULL,
1450 0x000000000000FDFDULL,
1451 0x0000000000FDFDFDULL,
1452 0x00000000FDFDFDFDULL,
1453 0x000000FDFDFDFDFDULL,
1454 0x0000FDFDFDFDFDFDULL,
1455 0x00FDFDFDFDFDFDFDULL,
1456 0xFDFDFDFDFDFDFDFDULL
1457 },
1458 {
1459 0x000000000000FDFDULL,
1460 0x0000000000FDFDFDULL,
1461 0x00000000FDFDFDFDULL,
1462 0x000000FDFDFDFDFDULL,
1463 0x0000FDFDFDFDFDFDULL,
1464 0x00FDFDFDFDFDFDFDULL,
1465 0xFDFDFDFDFDFDFDFDULL,
1466 0xFDFDFDFDFDFDFDFDULL
1467 },
1468 {
1469 0x0000000000FDFDFDULL,
1470 0x00000000FDFDFDFDULL,
1471 0x000000FDFDFDFDFDULL,
1472 0x0000FDFDFDFDFDFDULL,
1473 0x00FDFDFDFDFDFDFDULL,
1474 0xFDFDFDFDFDFDFDFDULL,
1475 0xFDFDFDFDFDFDFDFDULL,
1476 0xFDFDFDFDFDFDFDFDULL
1477 },
1478 {
1479 0x00000000FDFDFDFDULL,
1480 0x000000FDFDFDFDFDULL,
1481 0x0000FDFDFDFDFDFDULL,
1482 0x00FDFDFDFDFDFDFDULL,
1483 0xFDFDFDFDFDFDFDFDULL,
1484 0xFDFDFDFDFDFDFDFDULL,
1485 0xFDFDFDFDFDFDFDFDULL,
1486 0xFDFDFDFDFDFDFDFDULL
1487 },
1488 {
1489 0x000000FDFDFDFDFDULL,
1490 0x0000FDFDFDFDFDFDULL,
1491 0x00FDFDFDFDFDFDFDULL,
1492 0xFDFDFDFDFDFDFDFDULL,
1493 0xFDFDFDFDFDFDFDFDULL,
1494 0xFDFDFDFDFDFDFDFDULL,
1495 0xFDFDFDFDFDFDFDFDULL,
1496 0xFDFDFDFDFDFDFDFDULL
1497 },
1498 {
1499 0x0000FDFDFDFDFDFDULL,
1500 0x00FDFDFDFDFDFDFDULL,
1501 0xFDFDFDFDFDFDFDFDULL,
1502 0xFDFDFDFDFDFDFDFDULL,
1503 0xFDFDFDFDFDFDFDFDULL,
1504 0xFDFDFDFDFDFDFDFDULL,
1505 0xFDFDFDFDFDFDFDFDULL,
1506 0xFDFDFDFDFDFDFDFDULL
1507 },
1508 {
1509 0x00FDFDFDFDFDFDFDULL,
1510 0xFDFDFDFDFDFDFDFDULL,
1511 0xFDFDFDFDFDFDFDFDULL,
1512 0xFDFDFDFDFDFDFDFDULL,
1513 0xFDFDFDFDFDFDFDFDULL,
1514 0xFDFDFDFDFDFDFDFDULL,
1515 0xFDFDFDFDFDFDFDFDULL,
1516 0xFDFDFDFDFDFDFDFDULL
1517 },
1518 {
1519 0xFDFDFDFDFDFDFDFDULL,
1520 0xFDFDFDFDFDFDFDFDULL,
1521 0xFDFDFDFDFDFDFDFDULL,
1522 0xFDFDFDFDFDFDFDFDULL,
1523 0xFDFDFDFDFDFDFDFDULL,
1524 0xFDFDFDFDFDFDFDFDULL,
1525 0xFDFDFDFDFDFDFDFDULL,
1526 0xFDFDFDFDFDFDFDFDULL
1527 }
1528 }
1529 };
1530
1531 int32_t black_opening_count=0;
1532 int32_t black_opening_x,black_opening_y;
1533 int32_t black_opening_shape;
1534
1535 3204 int32_t choose_opening_shape()
1536 {
1537 // First, count how many bits are set
1538 3204 int32_t numBits=0;
1539 int32_t bitCounter;
1540
1541
2/2
✓ Branch 0 taken 16020 times.
✓ Branch 1 taken 3204 times.
19224 for(int32_t i=0; i<bosMAX; i++)
1542 {
1543
2/2
✓ Branch 0 taken 12600 times.
✓ Branch 1 taken 3420 times.
16020 if(COOLSCROLL&(1<<i))
1544 3420 numBits++;
1545 16020 }
1546
1547 // Shouldn't happen...
1548
1/2
✓ Branch 0 taken 3204 times.
✗ Branch 1 not taken.
3204 if(numBits==0)
1549 return bosCIRCLE;
1550
1551 // Pick a bit
1552 3204 bitCounter=zc_rand()%numBits+1;
1553
1554
2/2
✓ Branch 0 taken 4395 times.
✓ Branch 1 taken 26 times.
4421 for(int32_t i=0; i<bosMAX; i++)
1555 {
1556 // If this bit is set, decrement the bit counter
1557
2/2
✓ Branch 0 taken 1061 times.
✓ Branch 1 taken 3334 times.
4395 if(COOLSCROLL&(1<<i))
1558 3334 bitCounter--;
1559
1560 // When the counter hits 0, return a value based on
1561 // which bit it stopped on.
1562 // Reminder: enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
1563
2/2
✓ Branch 0 taken 3178 times.
✓ Branch 1 taken 1217 times.
4395 if(bitCounter==0)
1564 3178 return i;
1565 1217 }
1566
1567 // Shouldn't be necessary, but the compiler might complain, at least
1568 26 return bosCIRCLE;
1569 3204 }
1570
1571 727 void close_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1572 {
1573
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 727 times.
727 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1574
1575 727 int32_t w=256, h=224;
1576 727 int32_t blockrows=28, blockcolumns=32;
1577 727 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1578
1579
2/2
✓ Branch 0 taken 20356 times.
✓ Branch 1 taken 727 times.
21083 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1580 {
1581
2/2
✓ Branch 0 taken 651392 times.
✓ Branch 1 taken 20356 times.
671748 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1582 {
1583
2/2
✓ Branch 0 taken 269309 times.
✓ Branch 1 taken 382083 times.
651392 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1584 651392 }
1585 20356 }
1586
1587 727 black_opening_count = 66;
1588 727 black_opening_x = x;
1589 727 black_opening_y = y;
1590 727 lensclk = 0;
1591 //black_opening_shape=(black_opening_shape+1)%bosMAX;
1592
1593
1594
1/2
✓ Branch 0 taken 727 times.
✗ Branch 1 not taken.
727 if(black_opening_shape == bosFADEBLACK)
1595 {
1596 refreshTints();
1597 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1598 }
1599
2/2
✓ Branch 0 taken 723 times.
✓ Branch 1 taken 4 times.
727 if(wait)
1600 {
1601 4 FFCore.warpScriptCheck();
1602
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 264 times.
268 for(int32_t i=0; i<66; i++)
1603 {
1604 264 draw_screen(tmpscr);
1605 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
1606 264 advanceframe(true);
1607
1608
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 264 times.
264 if(Quit)
1609 {
1610 break;
1611 }
1612 264 }
1613 4 }
1614 727 }
1615
1616 2477 void open_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1617 {
1618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2477 times.
2477 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1619
1620 2477 int32_t w=256, h=224;
1621 2477 int32_t blockrows=28, blockcolumns=32;
1622 2477 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1623
1624
2/2
✓ Branch 0 taken 69356 times.
✓ Branch 1 taken 2477 times.
71833 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1625 {
1626
2/2
✓ Branch 0 taken 2219392 times.
✓ Branch 1 taken 69356 times.
2288748 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1627 {
1628
2/2
✓ Branch 0 taken 1095033 times.
✓ Branch 1 taken 1124359 times.
2219392 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1629 2219392 }
1630 69356 }
1631
1632 2477 black_opening_count = -66;
1633 2477 black_opening_x = x;
1634 2477 black_opening_y = y;
1635 2477 lensclk = 0;
1636
1/2
✓ Branch 0 taken 2477 times.
✗ Branch 1 not taken.
2477 if(black_opening_shape == bosFADEBLACK)
1637 {
1638 refreshTints();
1639 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1640 }
1641
2/2
✓ Branch 0 taken 367 times.
✓ Branch 1 taken 2110 times.
2477 if(wait)
1642 {
1643 2110 FFCore.warpScriptCheck();
1644
2/2
✓ Branch 0 taken 2109 times.
✓ Branch 1 taken 139263 times.
141372 for(int32_t i=0; i<66; i++)
1645 {
1646 139263 draw_screen(tmpscr);
1647 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
1648 139263 advanceframe(true);
1649
1650
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 139262 times.
139263 if(Quit)
1651 {
1652 1 break;
1653 }
1654 139262 }
1655 2110 }
1656 2477 }
1657
1658 210753 void black_opening(BITMAP *dest,int32_t x,int32_t y,int32_t a,int32_t max_a)
1659 {
1660 210753 clear_to_color(tmp_scr,BLACK);
1661 210753 int32_t w=256, h=224;
1662
1663
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9636 times.
✓ Branch 2 taken 660 times.
✓ Branch 3 taken 20262 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 180195 times.
210753 switch(black_opening_shape)
1664 {
1665 case bosOVAL:
1666 {
1667 9636 double new_w=(w/2)+abs(w/2-x);
1668 9636 double new_h=(h/2)+abs(h/2-y);
1669 9636 double b=sqrt(((new_w*new_w)/4)+(new_h*new_h));
1670 9636 ellipsefill(tmp_scr,x,y,int32_t(2*a*b/max_a)/8*8,int32_t(a*b/max_a)/8*8,0);
1671 9636 break;
1672 }
1673
1674 case bosTRIANGLE:
1675 {
1676 660 double new_w=(w/2)+abs(w/2-x);
1677 660 double new_h=(h/2)+abs(h/2-y);
1678 660 double r=a*(new_w*sqrt((double)3)+new_h)/max_a;
1679 660 double P2= (PI/2);
1680 660 double P23=(2*PI/3);
1681 660 double P43=(4*PI/3);
1682 660 double Pa= (-4*PI*a/(3*max_a));
1683 660 double angle=P2+Pa;
1684 660 double a0=angle;
1685 660 double a2=angle+P23;
1686 660 double a4=angle+P43;
1687 1320 triangle(tmp_scr, x+int32_t(zc::math::Cos(a0)*r), y-int32_t(zc::math::Sin(a0)*r),
1688 660 x+int32_t(zc::math::Cos(a2)*r), y-int32_t(zc::math::Sin(a2)*r),
1689 660 x+int32_t(zc::math::Cos(a4)*r), y-int32_t(zc::math::Sin(a4)*r),
1690 0);
1691 660 break;
1692 }
1693
1694 case bosSMAS:
1695 {
1696
2/2
✓ Branch 0 taken 7194 times.
✓ Branch 1 taken 13068 times.
20262 int32_t distance=zc_max(abs(w/2-x),abs(h/2-y))/8;
1697
1698
2/2
✓ Branch 0 taken 567336 times.
✓ Branch 1 taken 20262 times.
587598 for(int32_t blockrow=0; blockrow<28; ++blockrow) //30
1699 {
1700
2/2
✓ Branch 0 taken 4538688 times.
✓ Branch 1 taken 567336 times.
5106024 for(int32_t linerow=0; linerow<8; ++linerow)
1701 {
1702 4538688 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1703
1704
2/2
✓ Branch 0 taken 145238016 times.
✓ Branch 1 taken 4538688 times.
149776704 for(int32_t blockcolumn=0; blockcolumn<32; ++blockcolumn) //40
1705 {
1706 435714048 *triangleline=triangles[(screen_triangles[blockrow][blockcolumn]&0xC000)>>14]
1707
6/6
✓ Branch 0 taken 104912184 times.
✓ Branch 1 taken 40325832 times.
✓ Branch 2 taken 95821040 times.
✓ Branch 3 taken 49416976 times.
✓ Branch 4 taken 55495208 times.
✓ Branch 5 taken 40325832 times.
145238016 [zc_min(zc_max((((31+distance)*(max_a-a)/max_a)+((screen_triangles[blockrow][blockcolumn]&0x0FFF)-0x0100)-(15+distance)),0),15)]
1708 145238016 [linerow];
1709 145238016 ++triangleline;
1710
1711
2/2
✓ Branch 0 taken 127083264 times.
✓ Branch 1 taken 18154752 times.
145238016 if(linerow==0)
1712 {
1713 18154752 }
1714 145238016 }
1715 4538688 }
1716 567336 }
1717
1718 20262 break;
1719 }
1720
1721 case bosFADEBLACK:
1722 {
1723 if(black_opening_count<0)
1724 {
1725 black_fade(zc_min(-black_opening_count,63));
1726 }
1727 else if(black_opening_count>0)
1728 {
1729 black_fade(63-zc_max(black_opening_count-3,0));
1730 }
1731 else black_fade(0);
1732 return; //no blitting from tmp_scr!
1733 }
1734
1735 180195 case bosCIRCLE:
1736 default:
1737 {
1738 180195 double new_w=(w/2)+abs(w/2-x);
1739 180195 double new_h=(h/2)+abs(h/2-y);
1740 180195 int32_t r=int32_t(sqrt((new_w*new_w)+(new_h*new_h))*a/max_a);
1741 //circlefill(tmp_scr,x,y,a<<3,0);
1742 180195 circlefill(tmp_scr,x,y,r,0);
1743 180195 break;
1744 }
1745 }
1746
1747 210753 masked_blit(tmp_scr,dest,0,0,0,0,320,240);
1748 210753 }
1749
1750 // fadeamnt is 0-63
1751 void black_fade(int32_t fadeamnt)
1752 {
1753 fadeamnt = _rgb_scale_6[fadeamnt];
1754 for(int32_t i=0; i < 0xEF; i++)
1755 {
1756 RAMpal[i].r = vbound(tempblackpal[i].r-fadeamnt,0,255);
1757 RAMpal[i].g = vbound(tempblackpal[i].g-fadeamnt,0,255);
1758 RAMpal[i].b = vbound(tempblackpal[i].b-fadeamnt,0,255);
1759 }
1760
1761 refreshpal = true;
1762 }
1763
1764 //----------------------------------------------------------------
1765
1766 198173060 bool item_disabled(int32_t item) //is this item disabled?
1767 {
1768
2/2
✓ Branch 0 taken 14112335 times.
✓ Branch 1 taken 184060725 times.
198173060 return (unsigned(item) < MAXITEMS && game->items_off[item] != 0);
1769 }
1770
1771 15445683 bool can_use_item(int32_t item_type, int32_t item) //can Hero use this item?
1772 {
1773
2/2
✓ Branch 0 taken 188072 times.
✓ Branch 1 taken 15257611 times.
15445683 if(current_item(item_type, true) >=item)
1774 {
1775 188072 return true;
1776 }
1777
1778 15257611 return false;
1779 15445683 }
1780
1781 48060581 bool has_item(int32_t item_type, int32_t it) //does Hero possess this item?
1782 {
1783
5/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4374892 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4901587 times.
✓ Branch 6 taken 28694835 times.
✓ Branch 7 taken 9894813 times.
✓ Branch 8 taken 194454 times.
48060581 switch(item_type)
1784 {
1785 case itype_bomb:
1786 case itype_sbomb:
1787 {
1788 int32_t itemid = getItemID(itemsbuf, item_type, it);
1789
1790 if(itemid == -1)
1791 return false;
1792
1793 return (game->get_item(itemid));
1794 }
1795
1796 case itype_clock:
1797 {
1798 4374892 int32_t itemid = getItemID(itemsbuf, item_type, it);
1799
1800
2/4
✓ Branch 0 taken 4374892 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4374892 times.
✗ Branch 3 not taken.
4374892 if(itemid != -1 && (itemsbuf[itemid].flags & item_flag1)) //Active clock
1801 return (game->get_item(itemid));
1802 4374892 return Hero.getClock()?1:0;
1803 }
1804
1805 case itype_key:
1806 return (game->get_keys()>0);
1807
1808 case itype_magiccontainer:
1809 return (game->get_maxmagic()>=game->get_mp_per_block());
1810
1811 case itype_triforcepiece: //it: -2=any, -1=current level, other=that level
1812 {
1813
2/3
✓ Branch 0 taken 321216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4580371 times.
4901587 switch(it)
1814 {
1815 case -2:
1816 {
1817 for(int32_t i=0; i<MAXLEVELS; i++)
1818 {
1819 if(game->lvlitems[i]&liTRIFORCE)
1820 {
1821 return true;
1822 }
1823 }
1824
1825 return false;
1826 }
1827
1828 case -1:
1829 4580371 return (game->lvlitems[dlevel]&liTRIFORCE);
1830
1831 default:
1832
2/4
✓ Branch 0 taken 321216 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 321216 times.
321216 if(it>=0&&it<MAXLEVELS)
1833 {
1834 321216 return (game->lvlitems[it]&liTRIFORCE);
1835 }
1836
1837 break;
1838 }
1839
1840 return 0;
1841 }
1842
1843 case itype_map: //it: -2=any, -1=current level, other=that level
1844 {
1845
2/3
✓ Branch 0 taken 540402 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28154433 times.
28694835 switch(it)
1846 {
1847 case -2:
1848 {
1849 for(int32_t i=0; i<MAXLEVELS; i++)
1850 {
1851 if(game->lvlitems[i]&liMAP)
1852 {
1853 return true;
1854 }
1855 }
1856
1857 return false;
1858 }
1859
1860 case -1:
1861 28154433 return (game->lvlitems[dlevel]&liMAP)!=0;
1862
1863 default:
1864
2/4
✓ Branch 0 taken 540402 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 540402 times.
540402 if(it>=0&&it<MAXLEVELS)
1865 {
1866 540402 return (game->lvlitems[it]&liMAP)!=0;
1867 }
1868
1869 break;
1870 }
1871
1872 return 0;
1873 }
1874
1875 case itype_compass: //it: -2=any, -1=current level, other=that level
1876 {
1877
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 9894813 times.
9894813 switch(it)
1878 {
1879 case -2:
1880 {
1881 for(int32_t i=0; i<MAXLEVELS; i++)
1882 {
1883 if(game->lvlitems[i]&liCOMPASS)
1884 {
1885 return true;
1886 }
1887 }
1888
1889 return false;
1890 }
1891
1892 case -1:
1893 9894813 return (game->lvlitems[dlevel]&liCOMPASS)!=0;
1894
1895 default:
1896 if(it>=0&&it<MAXLEVELS)
1897 {
1898 return (game->lvlitems[it]&liCOMPASS)!=0;
1899 }
1900
1901 break;
1902 }
1903 return 0;
1904 }
1905
1906 case itype_bosskey: //it: -2=any, -1=current level, other=that level
1907 {
1908
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 194454 times.
194454 switch(it)
1909 {
1910 case -2:
1911 {
1912 for(int32_t i=0; i<MAXLEVELS; i++)
1913 {
1914 if(game->lvlitems[i]&liBOSSKEY)
1915 {
1916 return true;
1917 }
1918 }
1919
1920 return false;
1921 }
1922
1923 case -1:
1924 194454 return (game->lvlitems[dlevel]&liBOSSKEY)?1:0;
1925
1926 default:
1927 if(it>=0&&it<MAXLEVELS)
1928 {
1929 return (game->lvlitems[it]&liBOSSKEY)?1:0;
1930 }
1931 break;
1932 }
1933 return 0;
1934 }
1935
1936 default:
1937 int32_t itemid = getItemID(itemsbuf, item_type, it);
1938
1939 if(itemid == -1)
1940 return false;
1941
1942 return game->get_item(itemid);
1943 }
1944 48060581 }
1945
1946 149166432 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
1947 {
1948
9/9
✓ Branch 0 taken 4374892 times.
✓ Branch 1 taken 114167296 times.
✓ Branch 2 taken 4374892 times.
✓ Branch 3 taken 4374892 times.
✓ Branch 4 taken 4374892 times.
✓ Branch 5 taken 4374892 times.
✓ Branch 6 taken 4374892 times.
✓ Branch 7 taken 4374892 times.
✓ Branch 8 taken 4374892 times.
149166432 switch(item_type)
1949 {
1950 case itype_clock:
1951 {
1952 4374892 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
1953
1954
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4374892 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4374892 if(maxid != -1 && (itemsbuf[maxid].flags & item_flag1)) //Active clock
1955 return itemsbuf[maxid].fam_type;
1956
1957 4374892 return has_item(itype_clock,1) ? 1 : 0;
1958 }
1959
1960 case itype_key:
1961 4374892 return game->get_keys();
1962
1963 case itype_lkey:
1964 4374892 return game->lvlkeys[get_dlevel()];
1965
1966 case itype_magiccontainer:
1967 4374892 return game->get_maxmagic()/game->get_mp_per_block();
1968
1969 case itype_triforcepiece:
1970 {
1971 4374892 int count=0;
1972
1973
2/2
✓ Branch 0 taken 2239944704 times.
✓ Branch 1 taken 4374892 times.
2244319596 for(int i=0; i<MAXLEVELS; i++)
1974 {
1975 2239944704 count+=(game->lvlitems[i]&liTRIFORCE)?1:0;
1976 2239944704 }
1977
1978 4374892 return count;
1979 }
1980
1981 case itype_map:
1982 {
1983 4374892 int count=0;
1984
1985
2/2
✓ Branch 0 taken 2239944704 times.
✓ Branch 1 taken 4374892 times.
2244319596 for(int i=0; i<MAXLEVELS; i++)
1986 {
1987 2239944704 count+=(game->lvlitems[i]&liMAP)?1:0;
1988 2239944704 }
1989
1990 4374892 return count;
1991 }
1992
1993 case itype_compass:
1994 {
1995 4374892 int count=0;
1996
1997
2/2
✓ Branch 0 taken 2239944704 times.
✓ Branch 1 taken 4374892 times.
2244319596 for(int i=0; i<MAXLEVELS; i++)
1998 {
1999 2239944704 count+=(game->lvlitems[i]&liCOMPASS)?1:0;
2000 2239944704 }
2001
2002 4374892 return count;
2003 }
2004
2005 case itype_bosskey:
2006 {
2007 4374892 int count=0;
2008
2009
2/2
✓ Branch 0 taken 2239944704 times.
✓ Branch 1 taken 4374892 times.
2244319596 for(int i=0; i<MAXLEVELS; i++)
2010 {
2011 2239944704 count+=(game->lvlitems[i]&liBOSSKEY)?1:0;
2012 2239944704 }
2013
2014 4374892 return count;
2015 }
2016
2017 default:
2018 114167296 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
2019
2020
2/2
✓ Branch 0 taken 81136393 times.
✓ Branch 1 taken 33030903 times.
114167296 if(maxid == -1)
2021 81136393 return 0;
2022
2023 33030903 return itemsbuf[maxid].fam_type;
2024 }
2025 149166432 }
2026
2027 336 std::map<int32_t, int32_t> itemcache;
2028 336 std::map<int32_t, int32_t> itemcache_cost;
2029
2030 void removeFromItemCache(int32_t itemclass)
2031 {
2032 itemcache.erase(itemclass);
2033 itemcache_cost.erase(itemclass);
2034 cache_tile_mod_clear();
2035 }
2036
2037 12391014 void flushItemCache(bool justcost)
2038 {
2039 12391014 itemcache_cost.clear();
2040
2/2
✓ Branch 0 taken 12324745 times.
✓ Branch 1 taken 66269 times.
12391014 if(!justcost)
2041 66269 itemcache.clear();
2042
2/2
✓ Branch 0 taken 5825976 times.
✓ Branch 1 taken 6498769 times.
12324745 else if(replay_version_check(0,19))
2043 5825976 return;
2044
2045 6565038 cache_tile_mod_clear();
2046
2047 //also fix the active subscreen if items were deleted -DD
2048
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6565038 times.
6565038 if(game != NULL)
2049 {
2050 6565038 verifyBothWeapons();
2051 6565038 refresh_subscr_items();
2052 6565038 }
2053 12391014 }
2054
2055 // This is used often, so it should be as direct as possible.
2056 2973790562 int _c_item_id_internal(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2057 {
2058 2973790562 bool use_cost_cache = replay_version_check(19);
2059
2/2
✓ Branch 0 taken 2849499406 times.
✓ Branch 1 taken 124291156 times.
2973790562 if(jinx_check)
2060 {
2061 //special case for shields...
2062
3/4
✓ Branch 0 taken 39618683 times.
✓ Branch 1 taken 84672473 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 39618683 times.
124291156 if (itemtype == itype_shield && !HeroShieldClk())
2063 39618683 jinx_check = false;
2064
4/4
✓ Branch 0 taken 52067520 times.
✓ Branch 1 taken 32604953 times.
✓ Branch 2 taken 10856084 times.
✓ Branch 3 taken 41211436 times.
84672473 else if(!(HeroSwordClk() || HeroItemClk()))
2065 41211436 jinx_check = false; //not jinxed
2066 124291156 }
2067
4/4
✓ Branch 0 taken 114318 times.
✓ Branch 1 taken 2973676244 times.
✓ Branch 2 taken 1853 times.
✓ Branch 3 taken 112465 times.
2973790562 if(!Hero.BunnyClock() || itemtype == itype_pearl) // bunny_check does not apply
2068 2973678097 check_bunny = false;
2069
2/2
✓ Branch 0 taken 2917912356 times.
✓ Branch 1 taken 55878206 times.
2973790562 if(itemtype == itype_ring) checkmagic = true;
2070
4/4
✓ Branch 0 taken 2930329525 times.
✓ Branch 1 taken 43461037 times.
✓ Branch 2 taken 285018726 times.
✓ Branch 3 taken 23758619 times.
3282567907 if (!jinx_check && !check_bunny
2071
4/4
✓ Branch 0 taken 2930244668 times.
✓ Branch 1 taken 84857 times.
✓ Branch 2 taken 308777345 times.
✓ Branch 3 taken 2621467323 times.
2930329525 && (use_cost_cache || itemtype != itype_ring))
2072 {
2073
4/4
✓ Branch 0 taken 555039392 times.
✓ Branch 1 taken 2351446657 times.
✓ Branch 2 taken 243209289 times.
✓ Branch 3 taken 311830103 times.
2906486049 auto& cache = checkmagic && use_cost_cache ? itemcache_cost : itemcache;
2074 2906486049 auto res = cache.find(itemtype);
2075
2076
2/2
✓ Branch 0 taken 2762874342 times.
✓ Branch 1 taken 143611707 times.
2906486049 if(res != cache.end())
2077 2762874342 return res->second;
2078 143611707 }
2079
2080 210916220 int result = -1;
2081 210916220 int highestlevel = -1;
2082
2083
2/2
✓ Branch 0 taken 53994552320 times.
✓ Branch 1 taken 210916220 times.
54205468540 for(int i=0; i<MAXITEMS; i++)
2084 {
2085
6/6
✓ Branch 0 taken 5922085827 times.
✓ Branch 1 taken 48072466493 times.
✓ Branch 2 taken 95523707 times.
✓ Branch 3 taken 5826562120 times.
✓ Branch 4 taken 82048 times.
✓ Branch 5 taken 95441659 times.
53994552320 if(game->get_item(i) && itemsbuf[i].family==itemtype && !item_disabled(i))
2086 {
2087
4/4
✓ Branch 0 taken 90829065 times.
✓ Branch 1 taken 4612594 times.
✓ Branch 2 taken 2427248 times.
✓ Branch 3 taken 88401817 times.
95441659 if(checkmagic && itemtype != itype_magicring)
2088
2/2
✓ Branch 0 taken 88401200 times.
✓ Branch 1 taken 617 times.
88401817 if(!checkmagiccost(i))
2089 617 continue;
2090
6/6
✓ Branch 0 taken 87845631 times.
✓ Branch 1 taken 7595411 times.
✓ Branch 2 taken 1253626 times.
✓ Branch 3 taken 6341785 times.
✓ Branch 4 taken 4146834 times.
✓ Branch 5 taken 3448577 times.
95441042 if(jinx_check && (usesSwordJinx(i) ? HeroSwordClk() : HeroItemClk()))
2091
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3448577 times.
3448577 if(!(itemsbuf[i].flags & item_jinx_immune))
2092 3448577 continue;
2093
3/4
✓ Branch 0 taken 91665 times.
✓ Branch 1 taken 91900800 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 91665 times.
91992465 if(check_bunny && !checkbunny(i))
2094 91665 continue;
2095
2096
2/2
✓ Branch 0 taken 8381135 times.
✓ Branch 1 taken 83519665 times.
91900800 if(itemsbuf[i].fam_type >= highestlevel)
2097 {
2098 83519665 highestlevel = itemsbuf[i].fam_type;
2099 83519665 result=i;
2100 83519665 }
2101 91900800 }
2102 53991011461 }
2103
2104
4/4
✓ Branch 0 taken 167455183 times.
✓ Branch 1 taken 43461037 times.
✓ Branch 2 taken 84857 times.
✓ Branch 3 taken 167370326 times.
210916220 if(!(jinx_check || check_bunny)) //Can't cache jinx_check/check_bunny
2105 {
2106
2/2
✓ Branch 0 taken 127617390 times.
✓ Branch 1 taken 39752936 times.
167370326 if (use_cost_cache)
2107 {
2108
2/2
✓ Branch 0 taken 111890557 times.
✓ Branch 1 taken 15726833 times.
127617390 if (!checkmagic)
2109 15726833 itemcache[itemtype] = result;
2110
6/6
✓ Branch 0 taken 15726833 times.
✓ Branch 1 taken 111890557 times.
✓ Branch 2 taken 659717 times.
✓ Branch 3 taken 15067116 times.
✓ Branch 4 taken 647074 times.
✓ Branch 5 taken 12643 times.
127617390 if (checkmagic || result < 0 || checkmagiccost(result))
2111 127604747 itemcache_cost[itemtype] = result;
2112 127617390 }
2113 else
2114 {
2115 39752936 itemcache[itemtype] = result;
2116 }
2117 167370326 }
2118 210916220 return result;
2119 2973790562 }
2120
2121 // 'jinx_check' indicates that the highest level item *immune to jinxes* should be returned.
2122 2930829653 int current_item_id(int itype, bool checkmagic, bool jinx_check, bool check_bunny)
2123 {
2124
2/4
✓ Branch 0 taken 2930829653 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2930829653 times.
2930829653 if(itype < 0 || itype >= itype_max) return -1;
2125
1/2
✓ Branch 0 taken 2930829653 times.
✗ Branch 1 not taken.
2930829653 if(game->OverrideItems[itype] > -2)
2126 {
2127 auto ovid = game->OverrideItems[itype];
2128 if(ovid < 0 || ovid >= MAXITEMS)
2129 return -1;
2130 if(itemsbuf[ovid].family == itype)
2131 {
2132 if(itype == itype_magicring)
2133 checkmagic = false;
2134 else if(itype == itype_ring)
2135 checkmagic = true;
2136
2137 if(checkmagic && !checkmagiccost(ovid))
2138 return -1;
2139
2140 if (jinx_check && !checkitem_jinx(ovid))
2141 {
2142 return -1;
2143 }
2144 return ovid;
2145 }
2146 }
2147 2930829653 auto ret = _c_item_id_internal(itype,checkmagic,jinx_check,check_bunny);
2148
2/2
✓ Branch 0 taken 81330247 times.
✓ Branch 1 taken 2849499406 times.
2930829653 if(!jinx_check) //If not already a jinx-immune-only check...
2149 {
2150 //And the player IS jinxed...
2151
2/2
✓ Branch 0 taken 2806538497 times.
✓ Branch 1 taken 42960909 times.
2849499406 if(HeroIsJinxed())
2152 {
2153 //Then do a jinx-immune-only check here
2154 42960909 auto ret2 = _c_item_id_internal(itype,checkmagic,true,check_bunny);
2155 //And *IF IT FINDS A VALID ITEM*, return that one instead! -Em
2156 //Should NOT need a compat rule, as this should always return -1 in old quests.
2157
2/2
✓ Branch 0 taken 3265892 times.
✓ Branch 1 taken 39695017 times.
42960909 if(ret2 > -1) return ret2;
2158 39695017 }
2159 2846233514 }
2160 2927563761 return ret;
2161 2930829653 }
2162
2163 64796912 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2164 {
2165 64796912 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
2166
2/2
✓ Branch 0 taken 35028837 times.
✓ Branch 1 taken 29768075 times.
64796912 return (result<0) ? 0 : itemsbuf[result].power;
2167 }
2168
2169 26 int32_t heart_container_id()
2170 {
2171
1/2
✓ Branch 0 taken 754 times.
✗ Branch 1 not taken.
754 for(int32_t i=0; i<MAXITEMS; i++)
2172 {
2173
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 728 times.
754 if(itemsbuf[i].family == itype_heartcontainer)
2174 {
2175 26 return i;
2176 }
2177 728 }
2178 return -1;
2179 26 }
2180
2181 struct tilemod_cache_state_t
2182 {
2183
6/6
✓ Branch 0 taken 4374537 times.
✓ Branch 1 taken 8400992 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8400990 times.
✓ Branch 4 taken 353 times.
✓ Branch 5 taken 8400637 times.
21176521 bool operator==(const tilemod_cache_state_t&) const = default;
2184
2185 bool valid;
2186 bool bunny_clock;
2187 bool superman;
2188 int shield;
2189 };
2190 tilemod_cache_state_t tilemod_cache_state;
2191 int32_t tilemod_cache_value;
2192
2193 6566431 void cache_tile_mod_clear()
2194 {
2195 6566431 tilemod_cache_state = {false};
2196 6566431 }
2197
2198 12775529 int32_t item_tile_mod()
2199 {
2200 51102116 tilemod_cache_state_t state = {
2201 .valid = true,
2202 12775529 .bunny_clock = Hero.BunnyClock() != 0,
2203 12775529 .superman = Hero.superman,
2204 12775529 .shield = Hero.active_shield_id,
2205 };
2206
2/2
✓ Branch 0 taken 8400637 times.
✓ Branch 1 taken 4374892 times.
12775529 if (tilemod_cache_state == state)
2207 8400637 return tilemod_cache_value;
2208
2209 4374892 int32_t tile=0;
2210 4374892 bool check_bombcost = !get_qr(qr_BROKEN_BOMB_AMMO_COSTS);
2211
4/4
✓ Branch 0 taken 3961655 times.
✓ Branch 1 taken 413237 times.
✓ Branch 2 taken 3042145 times.
✓ Branch 3 taken 919510 times.
4374892 if(check_bombcost || game->get_bombs())
2212 {
2213 3455382 int32_t itemid = current_item_id(itype_bomb,check_bombcost);
2214
3/4
✓ Branch 0 taken 3395909 times.
✓ Branch 1 taken 59473 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3395909 times.
3455382 if(itemid > -1 && checkbunny(itemid))
2215 3395909 tile+=itemsbuf[itemid].ltm;
2216 3455382 }
2217
2218
4/4
✓ Branch 0 taken 3961655 times.
✓ Branch 1 taken 413237 times.
✓ Branch 2 taken 928295 times.
✓ Branch 3 taken 3033360 times.
4374892 if(check_bombcost || game->get_sbombs())
2219 {
2220 1341532 int32_t itemid = current_item_id(itype_sbomb,check_bombcost);
2221
3/4
✓ Branch 0 taken 928054 times.
✓ Branch 1 taken 413478 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 928054 times.
1341532 if(itemid > -1 && checkbunny(itemid))
2222 928054 tile+=itemsbuf[itemid].ltm;
2223 1341532 }
2224
2225
2/2
✓ Branch 0 taken 4370289 times.
✓ Branch 1 taken 4603 times.
4374892 if(current_item(itype_clock))
2226 {
2227 4603 int32_t itemid =
2228
2/2
✓ Branch 0 taken 4594 times.
✓ Branch 1 taken 9 times.
4603 get_qr(qr_HARDCODED_LITEM_LTMS)
2229 ? iClock
2230 9 : getHighestLevelEvenUnowned(itemsbuf, itype_clock);
2231
2/4
✓ Branch 0 taken 4603 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4603 times.
4603 if(itemid > -1 && checkbunny(itemid))
2232 4603 tile+=itemsbuf[itemid].ltm;
2233 4603 }
2234
2235
2/2
✓ Branch 0 taken 3766252 times.
✓ Branch 1 taken 608640 times.
4374892 if(current_item(itype_key))
2236 {
2237 608640 int32_t itemid =
2238
1/2
✓ Branch 0 taken 608640 times.
✗ Branch 1 not taken.
608640 get_qr(qr_HARDCODED_LITEM_LTMS)
2239 ? iKey
2240 : getHighestLevelEvenUnowned(itemsbuf, itype_key);
2241
2/4
✓ Branch 0 taken 608640 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 608640 times.
608640 if(itemid > -1 && checkbunny(itemid))
2242 608640 tile+=itemsbuf[itemid].ltm;
2243 608640 }
2244
2245
2/2
✓ Branch 0 taken 3874032 times.
✓ Branch 1 taken 500860 times.
4374892 if(current_item(itype_lkey))
2246 {
2247 500860 int32_t itemid =
2248
2/2
✓ Branch 0 taken 414146 times.
✓ Branch 1 taken 86714 times.
500860 get_qr(qr_HARDCODED_LITEM_LTMS)
2249 ? iLevelKey
2250 86714 : getHighestLevelEvenUnowned(itemsbuf, itype_lkey);
2251
2/4
✓ Branch 0 taken 500860 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 500860 times.
500860 if(itemid > -1 && checkbunny(itemid))
2252 500860 tile+=itemsbuf[itemid].ltm;
2253 500860 }
2254
2255
2/2
✓ Branch 0 taken 1540424 times.
✓ Branch 1 taken 2834468 times.
4374892 if(current_item(itype_map))
2256 {
2257 2834468 int32_t itemid =
2258
2/2
✓ Branch 0 taken 2823834 times.
✓ Branch 1 taken 10634 times.
2834468 get_qr(qr_HARDCODED_LITEM_LTMS)
2259 ? iMap
2260 10634 : getHighestLevelEvenUnowned(itemsbuf, itype_map);
2261
2/4
✓ Branch 0 taken 2834468 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2834468 times.
2834468 if(itemid > -1 && checkbunny(itemid))
2262 2834468 tile+=itemsbuf[itemid].ltm;
2263 2834468 }
2264
2265
2/2
✓ Branch 0 taken 2062903 times.
✓ Branch 1 taken 2311989 times.
4374892 if(current_item(itype_compass))
2266 {
2267 2311989 int32_t itemid =
2268
2/2
✓ Branch 0 taken 2295941 times.
✓ Branch 1 taken 16048 times.
2311989 get_qr(qr_HARDCODED_LITEM_LTMS)
2269 ? iCompass
2270 16048 : getHighestLevelEvenUnowned(itemsbuf, itype_compass);
2271
2/4
✓ Branch 0 taken 2311989 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2311989 times.
2311989 if(itemid > -1 && checkbunny(itemid))
2272 2311989 tile+=itemsbuf[itemid].ltm;
2273 2311989 }
2274
2275
2/2
✓ Branch 0 taken 1288476 times.
✓ Branch 1 taken 3086416 times.
4374892 if(current_item(itype_bosskey))
2276 {
2277 3086416 int32_t itemid =
2278
2/2
✓ Branch 0 taken 2993139 times.
✓ Branch 1 taken 93277 times.
3086416 get_qr(qr_HARDCODED_LITEM_LTMS)
2279 ? iBossKey
2280 93277 : getHighestLevelEvenUnowned(itemsbuf, itype_bosskey);
2281
2/4
✓ Branch 0 taken 3086416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3086416 times.
3086416 if(itemid > -1 && checkbunny(itemid))
2282 3086416 tile+=itemsbuf[itemid].ltm;
2283 3086416 }
2284
2285
2/2
✓ Branch 0 taken 48201 times.
✓ Branch 1 taken 4326691 times.
4374892 if(current_item(itype_magiccontainer))
2286 {
2287 4326691 int32_t itemid =
2288
2/2
✓ Branch 0 taken 3895892 times.
✓ Branch 1 taken 430799 times.
4326691 get_qr(qr_HARDCODED_LITEM_LTMS)
2289 ? iMagicC
2290 430799 : getHighestLevelEvenUnowned(itemsbuf, itype_magiccontainer);
2291
3/4
✓ Branch 0 taken 4326691 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 4326674 times.
4326691 if(itemid > -1 && checkbunny(itemid))
2292 4326674 tile+=itemsbuf[itemid].ltm;
2293 4326691 }
2294
2295
2/2
✓ Branch 0 taken 1305414 times.
✓ Branch 1 taken 3069478 times.
4374892 if(current_item(itype_triforcepiece))
2296 {
2297 3069478 int32_t itemid =
2298
1/2
✓ Branch 0 taken 3069478 times.
✗ Branch 1 not taken.
3069478 get_qr(qr_HARDCODED_LITEM_LTMS)
2299 ? iTriforce
2300 : getHighestLevelEvenUnowned(itemsbuf, itype_triforcepiece);
2301
2/4
✓ Branch 0 taken 3069478 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3069478 times.
3069478 if(itemid > -1 && checkbunny(itemid))
2302 3069478 tile+=itemsbuf[itemid].ltm;
2303 3069478 }
2304
2305
2/2
✓ Branch 0 taken 2239944704 times.
✓ Branch 1 taken 4374892 times.
2244319596 for(int32_t i=0; i<itype_max; i++)
2306 {
2307
2/2
✓ Branch 0 taken 2019299328 times.
✓ Branch 1 taken 220645376 times.
2239944704 if(!get_qr(qr_HARDCODED_LITEM_LTMS))
2308 {
2309
2/2
✓ Branch 0 taken 4309480 times.
✓ Branch 1 taken 216335896 times.
220645376 switch(i)
2310 {
2311 case itype_bomb:
2312 case itype_sbomb:
2313 case itype_clock:
2314 case itype_key:
2315 case itype_lkey:
2316 case itype_map:
2317 case itype_compass:
2318 case itype_bosskey:
2319 case itype_magiccontainer:
2320 case itype_triforcepiece:
2321 4309480 continue; //already handled
2322 }
2323 216335896 }
2324 2235635224 int32_t itemid = current_item_id(i,false);
2325
2/2
✓ Branch 0 taken 2231260332 times.
✓ Branch 1 taken 4374892 times.
2235635224 if(i == itype_shield)
2326 4374892 itemid = getCurrentShield(false);
2327
2328
4/4
✓ Branch 0 taken 114074356 times.
✓ Branch 1 taken 2121560868 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 114074355 times.
2235635224 if(itemid < 0 || !checkbunny(itemid))
2329 2121560869 continue;
2330
2331 114074355 itemdata const& itm = itemsbuf[itemid];
2332
2333
2/2
✓ Branch 0 taken 110411502 times.
✓ Branch 1 taken 3662853 times.
114074355 switch(itm.family)
2334 {
2335 case itype_shield:
2336
1/2
✓ Branch 0 taken 3662853 times.
✗ Branch 1 not taken.
3662853 if(itm.flags & item_flag9) //active shield
2337 {
2338 if(!usingActiveShield(itemid))
2339 {
2340 tile+=itm.misc6; //'Inactive PTM'
2341 continue;
2342 }
2343 }
2344 3662853 break;
2345 }
2346
2347 114074355 tile+=itm.ltm;
2348 114074355 }
2349
2350 4374892 tilemod_cache_value = tile;
2351 4374892 tilemod_cache_state = state;
2352 4374892 return tile;
2353 12775529 }
2354
2355 12775529 int32_t bunny_tile_mod()
2356 {
2357
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 12773659 times.
12775529 if(Hero.BunnyClock())
2358 {
2359 1870 return game->get_bunny_ltm();
2360 }
2361 12773659 return 0;
2362 12775529 }
2363
2364 // Hints are drawn on a separate layer to combo reveals.
2365 20010 void draw_lens_under(BITMAP *dest, bool layer)
2366 {
2367 //Lens flag 1: Replacement for qr_LENSHINTS; if set, lens will show hints. Does nothing if flag 2 is set.
2368 //Lens flag 2: Disable "hints", prevent rendering of Secret Combos
2369 //Lens flag 3: Don't show armos/chest/dive items
2370 //Lens flag 4: Show Raft Paths
2371 //Lens flag 5: Show Invisible Enemies
2372
4/4
✓ Branch 0 taken 456 times.
✓ Branch 1 taken 19554 times.
✓ Branch 2 taken 9777 times.
✓ Branch 3 taken 9777 times.
20010 bool hints = (itemsbuf[Hero.getLastLensID()].flags & item_flag2) ? false : (layer && (itemsbuf[Hero.getLastLensID()].flags & item_flag1));
2373
2374 20010 int32_t strike_hint_table[11]=
2375 {
2376 mfARROW, mfBOMB, mfBRANG, mfWANDMAGIC,
2377 mfSWORD, mfREFMAGIC, mfHOOKSHOT,
2378 mfREFFIREBALL, mfHAMMER, mfSWORDBEAM, mfWAND
2379 };
2380
2381 {
2382 20010 int32_t blink_rate=flash_reduction_enabled()?6:1;
2383 20010 int32_t tempitem, tempweapon=0;
2384 20010 strike_hint=strike_hint_table[strike_hint_counter];
2385
2386
2/2
✓ Branch 0 taken 19412 times.
✓ Branch 1 taken 598 times.
20010 if(strike_hint_timer>32)
2387 {
2388 598 strike_hint_timer=0;
2389 598 strike_hint_counter=((strike_hint_counter+1)%11);
2390 598 }
2391
2392 20010 ++strike_hint_timer;
2393
2394
2/2
✓ Branch 0 taken 3521760 times.
✓ Branch 1 taken 20010 times.
3541770 for(int32_t i=0; i<176; i++)
2395 {
2396 3521760 int32_t x = (i & 15) << 4;
2397 3521760 int32_t y = (i & 0xF0) + playing_field_offset;
2398 3521760 int32_t tempitemx=-16, tempitemy=-16;
2399 3521760 int32_t tempweaponx=-16, tempweapony=-16;
2400
2401
2/2
✓ Branch 0 taken 7043520 times.
✓ Branch 1 taken 3521760 times.
10565280 for(int32_t iter=0; iter<2; ++iter)
2402 {
2403 7043520 int32_t checkflag=0;
2404
2405
2/2
✓ Branch 0 taken 3521760 times.
✓ Branch 1 taken 3521760 times.
7043520 if(iter==0)
2406 {
2407 3521760 checkflag=combobuf[tmpscr->data[i]].flag;
2408 3521760 }
2409 else
2410 {
2411 3521760 checkflag=tmpscr->sflag[i];
2412 }
2413
2414
2/2
✓ Branch 0 taken 7042422 times.
✓ Branch 1 taken 1098 times.
7043520 if(checkflag==mfSTRIKE)
2415 {
2416
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 906 times.
1098 if(!hints)
2417 {
2418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSTRIKE],tmpscr->secretcset[sSTRIKE]);
2419 906 }
2420 else
2421 {
2422 192 checkflag = strike_hint;
2423 }
2424 1098 }
2425
2426
21/36
✓ Branch 0 taken 6894870 times.
✓ Branch 1 taken 3258 times.
✓ Branch 2 taken 108898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2602 times.
✓ Branch 5 taken 28750 times.
✓ Branch 6 taken 2418 times.
✓ Branch 7 taken 504 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 814 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 93 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 25 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 138 times.
✓ Branch 21 taken 16 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 7 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✓ Branch 32 taken 35 times.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 906 times.
7043520 switch(checkflag)
2427 {
2428 case 0:
2429 case mfZELDA:
2430 case mfPUSHED:
2431 case mfENEMY0:
2432 case mfENEMY1:
2433 case mfENEMY2:
2434 case mfENEMY3:
2435 case mfENEMY4:
2436 case mfENEMY5:
2437 case mfENEMY6:
2438 case mfENEMY7:
2439 case mfENEMY8:
2440 case mfENEMY9:
2441 case mfSINGLE:
2442 case mfSINGLE16:
2443 case mfNOENEMY:
2444 case mfTRAP_H:
2445 case mfTRAP_V:
2446 case mfTRAP_4:
2447 case mfTRAP_LR:
2448 case mfTRAP_UD:
2449 case mfNOGROUNDENEMY:
2450 case mfNOBLOCKS:
2451 case mfSCRIPT1:
2452 case mfSCRIPT2:
2453 case mfSCRIPT3:
2454 case mfSCRIPT4:
2455 case mfSCRIPT5:
2456 case mfSCRIPT6:
2457 case mfSCRIPT7:
2458 case mfSCRIPT8:
2459 case mfSCRIPT9:
2460 case mfSCRIPT10:
2461 case mfSCRIPT11:
2462 case mfSCRIPT12:
2463 case mfSCRIPT13:
2464 case mfSCRIPT14:
2465 case mfSCRIPT15:
2466 case mfSCRIPT16:
2467 case mfSCRIPT17:
2468 case mfSCRIPT18:
2469 case mfSCRIPT19:
2470 case mfSCRIPT20:
2471 case mfPITHOLE:
2472 case mfPITFALLFLOOR:
2473 case mfLAVA:
2474 case mfICE:
2475 case mfICEDAMAGE:
2476 case mfDAMAGE1:
2477 case mfDAMAGE2:
2478 case mfDAMAGE4:
2479 case mfDAMAGE8:
2480 case mfDAMAGE16:
2481 case mfDAMAGE32:
2482 case mfFREEZEALL:
2483 case mfFREZEALLANSFFCS:
2484 case mfFREEZEFFCSOLY:
2485 case mfSCRITPTW1TRIG:
2486 case mfSCRITPTW2TRIG:
2487 case mfSCRITPTW3TRIG:
2488 case mfSCRITPTW4TRIG:
2489 case mfSCRITPTW5TRIG:
2490 case mfSCRITPTW6TRIG:
2491 case mfSCRITPTW7TRIG:
2492 case mfSCRITPTW8TRIG:
2493 case mfSCRITPTW9TRIG:
2494 case mfSCRITPTW10TRIG:
2495 case mfTROWEL:
2496 case mfTROWELNEXT:
2497 case mfTROWELSPECIALITEM:
2498 case mfSLASHPOT:
2499 case mfLIFTPOT:
2500 case mfLIFTORSLASH:
2501 case mfLIFTROCK:
2502 case mfLIFTROCKHEAVY:
2503 case mfDROPITEM:
2504 case mfSPECIALITEM:
2505 case mfDROPKEY:
2506 case mfDROPLKEY:
2507 case mfDROPCOMPASS:
2508 case mfDROPMAP:
2509 case mfDROPBOSSKEY:
2510 case mfSPAWNNPC:
2511 case mfSWITCHHOOK:
2512 case mfSIDEVIEWLADDER:
2513 case mfSIDEVIEWPLATFORM:
2514 case mfNOENEMYSPAWN:
2515 case mfENEMYALL:
2516 case mfNOMIRROR:
2517 case mfUNSAFEGROUND:
2518 case mf168:
2519 case mf169:
2520 case mf170:
2521 case mf171:
2522 case mf172:
2523 case mf173:
2524 case mf174:
2525 case mf175:
2526 case mf176:
2527 case mf177:
2528 case mf178:
2529 case mf179:
2530 case mf180:
2531 case mf181:
2532 case mf182:
2533 case mf183:
2534 case mf184:
2535 case mf185:
2536 case mf186:
2537 case mf187:
2538 case mf188:
2539 case mf189:
2540 case mf190:
2541 case mf191:
2542 case mf192:
2543 case mf193:
2544 case mf194:
2545 case mf195:
2546 case mf196:
2547 case mf197:
2548 case mf198:
2549 case mf199:
2550 case mf200:
2551 case mf201:
2552 case mf202:
2553 case mf203:
2554 case mf204:
2555 case mf205:
2556 case mf206:
2557 case mf207:
2558 case mf208:
2559 case mf209:
2560 case mf210:
2561 case mf211:
2562 case mf212:
2563 case mf213:
2564 case mf214:
2565 case mf215:
2566 case mf216:
2567 case mf217:
2568 case mf218:
2569 case mf219:
2570 case mf220:
2571 case mf221:
2572 case mf222:
2573 case mf223:
2574 case mf224:
2575 case mf225:
2576 case mf226:
2577 case mf227:
2578 case mf228:
2579 case mf229:
2580 case mf230:
2581 case mf231:
2582 case mf232:
2583 case mf233:
2584 case mf234:
2585 case mf235:
2586 case mf236:
2587 case mf237:
2588 case mf238:
2589 case mf239:
2590 case mf240:
2591 case mf241:
2592 case mf242:
2593 case mf243:
2594 case mf244:
2595 case mf245:
2596 case mf246:
2597 case mf247:
2598 case mf248:
2599 case mf249:
2600 case mf250:
2601 case mf251:
2602 case mf252:
2603 case mf253:
2604 case mf254:
2605 case mfEXTENDED:
2606 6894870 break;
2607
2608 case mfPUSHUD:
2609 case mfPUSHLR:
2610 case mfPUSH4:
2611 case mfPUSHU:
2612 case mfPUSHD:
2613 case mfPUSHL:
2614 case mfPUSHR:
2615 case mfPUSHUDNS:
2616 case mfPUSHLRNS:
2617 case mfPUSH4NS:
2618 case mfPUSHUNS:
2619 case mfPUSHDNS:
2620 case mfPUSHLNS:
2621 case mfPUSHRNS:
2622 case mfPUSHUDINS:
2623 case mfPUSHLRINS:
2624 case mfPUSH4INS:
2625 case mfPUSHUINS:
2626 case mfPUSHDINS:
2627 case mfPUSHLINS:
2628 case mfPUSHRINS:
2629
3/4
✓ Branch 0 taken 1939 times.
✓ Branch 1 taken 1319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
3258 if(!hints && ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&16))
2630
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1939 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1939 || ((get_debug() && zc_getkey(KEY_N)) && (frame&16))))
2631 {
2632 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->undercombo,tmpscr->undercset);
2633 }
2634
2635
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3258 times.
3258 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2636
3/6
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 738 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 738 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3258 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2637 {
2638
2/2
✓ Branch 0 taken 1488 times.
✓ Branch 1 taken 1032 times.
2520 if(hints)
2639 {
2640
3/3
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 897 times.
1032 switch(combobuf[tmpscr->data[i]].type)
2641 {
2642 case cPUSH_HEAVY:
2643 case cPUSH_HW:
2644 72 tempitem=getItemIDPower(itemsbuf,itype_bracelet,1);
2645 72 tempitemx=x, tempitemy=y;
2646
2647
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(tempitem>-1)
2648 72 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2649
2650 72 break;
2651
2652 case cPUSH_HEAVY2:
2653 case cPUSH_HW2:
2654 63 tempitem=getItemIDPower(itemsbuf,itype_bracelet,2);
2655 63 tempitemx=x, tempitemy=y;
2656
2657
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 63 times.
63 if(tempitem>-1)
2658 63 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2659
2660 63 break;
2661 }
2662 1032 }
2663 2520 }
2664
2665 3258 break;
2666
2667 case mfWHISTLE:
2668
1/2
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
2418 if(hints)
2669 {
2670 tempitem=getItemID(itemsbuf,itype_whistle,1);
2671
2672 if(tempitem<0) break;
2673
2674 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2675 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2676 {
2677 tempitemx=x;
2678 tempitemy=y;
2679 }
2680
2681 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2682 }
2683
2684 2418 break;
2685
2686 //Why is this here?
2687 case mfFAIRY:
2688 case mfMAGICFAIRY:
2689 case mfALLFAIRY:
2690 if(hints)
2691 {
2692 tempitem=getItemID(itemsbuf, itype_fairy,1);//iFairyMoving;
2693
2694 if(tempitem < 0) break;
2695
2696 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2697 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2698 {
2699 tempitemx=x;
2700 tempitemy=y;
2701 }
2702
2703 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2704 }
2705
2706 break;
2707
2708 case mfANYFIRE:
2709
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 if(!hints)
2710 {
2711
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sBCANDLE],tmpscr->secretcset[sBCANDLE]);
2712 252 }
2713 else
2714 {
2715 252 tempitem=getItemID(itemsbuf,itype_candle,1);
2716
2717
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(tempitem<0) break;
2718
2719
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2720
3/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
252 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2721 {
2722 189 tempitemx=x;
2723 189 tempitemy=y;
2724 189 }
2725
2726 252 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2727 }
2728
2729 504 break;
2730
2731 case mfSTRONGFIRE:
2732 if(!hints)
2733 {
2734 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sRCANDLE],tmpscr->secretcset[sRCANDLE]);
2735 }
2736 else
2737 {
2738 tempitem=getItemID(itemsbuf,itype_candle,2);
2739
2740 if(tempitem<0) break;
2741
2742 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2743 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2744 {
2745 tempitemx=x;
2746 tempitemy=y;
2747 }
2748
2749 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2750 }
2751
2752 break;
2753
2754 case mfMAGICFIRE:
2755 if(!hints)
2756 {
2757 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sWANDFIRE],tmpscr->secretcset[sWANDFIRE]);
2758 }
2759 else
2760 {
2761 tempitem=getItemID(itemsbuf,itype_wand,1);
2762
2763 if(tempitem<0) break;
2764
2765 tempweapon=wFire;
2766
2767 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2768 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2769 {
2770 tempitemx=x;
2771 tempitemy=y;
2772 }
2773 else
2774 {
2775 tempweaponx=x;
2776 tempweapony=y;
2777 }
2778
2779 putweapon(dest,tempweaponx,tempweapony,tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2780 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2781 }
2782
2783 break;
2784
2785 case mfDIVINEFIRE:
2786 if(!hints)
2787 {
2788 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sDIVINEFIRE],tmpscr->secretcset[sDIVINEFIRE]);
2789 }
2790 else
2791 {
2792 tempitem=getItemID(itemsbuf,itype_divinefire,1);
2793
2794 if(tempitem<0) break;
2795
2796 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2797 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2798 {
2799 tempitemx=x;
2800 tempitemy=y;
2801 }
2802
2803 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2804 }
2805
2806 break;
2807
2808 case mfARROW:
2809
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 732 times.
814 if(!hints)
2810 {
2811
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 732 times.
732 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sARROW],tmpscr->secretcset[sARROW]);
2812 732 }
2813 else
2814 {
2815 82 tempitem=getItemID(itemsbuf,itype_arrow,1);
2816
2817
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(tempitem<0) break;
2818
2819
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2820
3/6
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
82 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2821 {
2822 61 tempitemx=x;
2823 61 tempitemy=y;
2824 61 }
2825
2826 82 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2827 }
2828
2829 814 break;
2830
2831 case mfSARROW:
2832 if(!hints)
2833 {
2834 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSARROW],tmpscr->secretcset[sSARROW]);
2835 }
2836 else
2837 {
2838 tempitem=getItemID(itemsbuf,itype_arrow,2);
2839
2840 if(tempitem<0) break;
2841
2842 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2843 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2844 {
2845 tempitemx=x;
2846 tempitemy=y;
2847 }
2848
2849 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2850 }
2851
2852 break;
2853
2854 case mfGARROW:
2855 if(!hints)
2856 {
2857 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sGARROW],tmpscr->secretcset[sGARROW]);
2858 }
2859 else
2860 {
2861 tempitem=getItemID(itemsbuf,itype_arrow,3);
2862
2863 if(tempitem<0) break;
2864
2865 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2866 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2867 {
2868 tempitemx=x;
2869 tempitemy=y;
2870 }
2871
2872 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2873 }
2874
2875 break;
2876
2877 case mfBOMB:
2878
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 76 times.
93 if(!hints)
2879 {
2880
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sBOMB],tmpscr->secretcset[sBOMB]);
2881 76 }
2882 else
2883 {
2884 //tempitem=getItemID(itemsbuf,itype_bomb,1);
2885 17 tempweapon = wLitBomb;
2886
2887 //if (tempitem<0) break;
2888
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2889
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2890 {
2891 12 tempweaponx=x;
2892 12 tempweapony=y;
2893 12 }
2894
2895 17 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2896 }
2897
2898 93 break;
2899
2900 case mfSBOMB:
2901
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if(!hints)
2902 {
2903
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSBOMB],tmpscr->secretcset[sSBOMB]);
2904 48 }
2905 else
2906 {
2907 //tempitem=getItemID(itemsbuf,itype_sbomb,1);
2908 //if (tempitem<0) break;
2909 48 tempweapon = wLitSBomb;
2910
2911
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2912
3/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2913 {
2914 36 tempweaponx=x;
2915 36 tempweapony=y;
2916 36 }
2917
2918 48 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2919 }
2920
2921 96 break;
2922
2923 case mfARMOS_SECRET:
2924
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(!hints)
2925 {
2926
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSTAIRS],tmpscr->secretcset[sSTAIRS]);
2927 12 }
2928 24 break;
2929
2930 case mfBRANG:
2931
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
25 if(!hints)
2932 {
2933
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sBRANG],tmpscr->secretcset[sBRANG]);
2934 20 }
2935 else
2936 {
2937 5 tempitem=getItemID(itemsbuf,itype_brang,1);
2938
2939
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(tempitem<0) break;
2940
2941
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2942
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2943 {
2944 4 tempitemx=x;
2945 4 tempitemy=y;
2946 4 }
2947
2948 5 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2949 }
2950
2951 25 break;
2952
2953 case mfMBRANG:
2954 if(!hints)
2955 {
2956 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sMBRANG],tmpscr->secretcset[sMBRANG]);
2957 }
2958 else
2959 {
2960 tempitem=getItemID(itemsbuf,itype_brang,2);
2961
2962 if(tempitem<0) break;
2963
2964 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2965 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2966 {
2967 tempitemx=x;
2968 tempitemy=y;
2969 }
2970
2971 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2972 }
2973
2974 break;
2975
2976 case mfFBRANG:
2977 if(!hints)
2978 {
2979 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sFBRANG],tmpscr->secretcset[sFBRANG]);
2980 }
2981 else
2982 {
2983 tempitem=getItemID(itemsbuf,itype_brang,3);
2984
2985 if(tempitem<0) break;
2986
2987 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2988 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2989 {
2990 tempitemx=x;
2991 tempitemy=y;
2992 }
2993
2994 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2995 }
2996
2997 break;
2998
2999 case mfWANDMAGIC:
3000
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!hints)
3001 {
3002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sWANDMAGIC],tmpscr->secretcset[sWANDMAGIC]);
3003 138 }
3004 else
3005 {
3006 tempitem=getItemID(itemsbuf,itype_wand,1);
3007
3008 if(tempitem<0) break;
3009
3010 tempweapon=itemsbuf[tempitem].wpn3;
3011
3012 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3013 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3014 {
3015 tempitemx=x;
3016 tempitemy=y;
3017 }
3018 else
3019 {
3020 tempweaponx=x;
3021 tempweapony=y;
3022 --lens_hint_weapon[wMagic][4];
3023
3024 if(lens_hint_weapon[wMagic][4]<-8)
3025 {
3026 lens_hint_weapon[wMagic][4]=8;
3027 }
3028 }
3029
3030 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3031 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3032 }
3033
3034 138 break;
3035
3036 case mfREFMAGIC:
3037
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3038 {
3039 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sREFMAGIC],tmpscr->secretcset[sREFMAGIC]);
3040 }
3041 else
3042 {
3043 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3044
3045
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3046
3047 16 tempweapon=ewMagic;
3048
3049
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3050
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3051 {
3052 13 tempitemx=x;
3053 13 tempitemy=y;
3054 13 }
3055 else
3056 {
3057 3 tempweaponx=x;
3058 3 tempweapony=y;
3059
3060
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if(lens_hint_weapon[ewMagic][2]==up)
3061 {
3062 1 --lens_hint_weapon[ewMagic][4];
3063 1 }
3064 else
3065 {
3066 2 ++lens_hint_weapon[ewMagic][4];
3067 }
3068
3069
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(lens_hint_weapon[ewMagic][4]>8)
3070 {
3071 lens_hint_weapon[ewMagic][2]=up;
3072 }
3073
3074
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(lens_hint_weapon[ewMagic][4]<=0)
3075 {
3076 2 lens_hint_weapon[ewMagic][2]=down;
3077 2 }
3078 }
3079
3080 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3081 16 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, lens_hint_weapon[ewMagic][2], lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3082 }
3083
3084 16 break;
3085
3086 case mfREFFIREBALL:
3087
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3088 {
3089 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sREFFIREBALL],tmpscr->secretcset[sREFFIREBALL]);
3090 }
3091 else
3092 {
3093 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3094
3095
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3096
3097 16 tempweapon=ewFireball;
3098
3099
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3100
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3101 {
3102 12 tempitemx=x;
3103 12 tempitemy=y;
3104 12 tempweaponx=x;
3105 12 tempweapony=y;
3106 12 ++lens_hint_weapon[ewFireball][3];
3107
3108
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
12 if(lens_hint_weapon[ewFireball][3]>8)
3109 {
3110 1 lens_hint_weapon[ewFireball][3]=-8;
3111 1 lens_hint_weapon[ewFireball][4]=8;
3112 1 }
3113
3114
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if(lens_hint_weapon[ewFireball][3]>0)
3115 {
3116 8 ++lens_hint_weapon[ewFireball][4];
3117 8 }
3118 else
3119 {
3120 4 --lens_hint_weapon[ewFireball][4];
3121 }
3122 12 }
3123
3124 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3125 16 putweapon(dest,tempweaponx+lens_hint_weapon[tempweapon][3],tempweapony+lens_hint_weapon[ewFireball][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3126 }
3127
3128 16 break;
3129
3130 case mfSWORD:
3131
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!hints)
3132 {
3133 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSWORD],tmpscr->secretcset[sSWORD]);
3134 }
3135 else
3136 {
3137 7 tempitem=getItemID(itemsbuf,itype_sword,1);
3138
3139
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(tempitem<0) break;
3140
3141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3142
3/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3143 {
3144 5 tempitemx=x;
3145 5 tempitemy=y;
3146 5 }
3147
3148 7 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3149 }
3150
3151 7 break;
3152
3153 case mfWSWORD:
3154 if(!hints)
3155 {
3156 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sWSWORD],tmpscr->secretcset[sWSWORD]);
3157 }
3158 else
3159 {
3160 tempitem=getItemID(itemsbuf,itype_sword,2);
3161
3162 if(tempitem<0) break;
3163
3164 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3165 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3166 {
3167 tempitemx=x;
3168 tempitemy=y;
3169 }
3170
3171 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3172 }
3173
3174 break;
3175
3176 case mfMSWORD:
3177 if(!hints)
3178 {
3179 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sMSWORD],tmpscr->secretcset[sMSWORD]);
3180 }
3181 else
3182 {
3183 tempitem=getItemID(itemsbuf,itype_sword,3);
3184
3185 if(tempitem<0) break;
3186
3187 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3188 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3189 {
3190 tempitemx=x;
3191 tempitemy=y;
3192 }
3193
3194 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3195 }
3196
3197 break;
3198
3199 case mfXSWORD:
3200 if(!hints)
3201 {
3202 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sXSWORD],tmpscr->secretcset[sXSWORD]);
3203 }
3204 else
3205 {
3206 tempitem=getItemID(itemsbuf,itype_sword,4);
3207
3208 if(tempitem<0) break;
3209
3210 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3211 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3212 {
3213 tempitemx=x;
3214 tempitemy=y;
3215 }
3216
3217 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3218 }
3219
3220 break;
3221
3222 case mfSWORDBEAM:
3223
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3224 {
3225 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sSWORDBEAM],tmpscr->secretcset[sSWORDBEAM]);
3226 }
3227 else
3228 {
3229 16 tempitem=getItemID(itemsbuf,itype_sword,1);
3230
3231
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3232
3233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3234
3/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3235 {
3236 11 tempitemx=x;
3237 11 tempitemy=y;
3238 11 }
3239
3240 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 1);
3241 }
3242
3243 16 break;
3244
3245 case mfWSWORDBEAM:
3246 if(!hints)
3247 {
3248 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sWSWORDBEAM],tmpscr->secretcset[sWSWORDBEAM]);
3249 }
3250 else
3251 {
3252 tempitem=getItemID(itemsbuf,itype_sword,2);
3253
3254 if(tempitem<0) break;
3255
3256 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3257 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3258 {
3259 tempitemx=x;
3260 tempitemy=y;
3261 }
3262
3263 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 2);
3264 }
3265
3266 break;
3267
3268 case mfMSWORDBEAM:
3269 if(!hints)
3270 {
3271 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sMSWORDBEAM],tmpscr->secretcset[sMSWORDBEAM]);
3272 }
3273 else
3274 {
3275 tempitem=getItemID(itemsbuf,itype_sword,3);
3276
3277 if(tempitem<0) break;
3278
3279 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3280 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3281 {
3282 tempitemx=x;
3283 tempitemy=y;
3284 }
3285
3286 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 3);
3287 }
3288
3289 break;
3290
3291 case mfXSWORDBEAM:
3292 if(!hints)
3293 {
3294 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sXSWORDBEAM],tmpscr->secretcset[sXSWORDBEAM]);
3295 }
3296 else
3297 {
3298 tempitem=getItemID(itemsbuf,itype_sword,4);
3299
3300 if(tempitem<0) break;
3301
3302 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3303 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3304 {
3305 tempitemx=x;
3306 tempitemy=y;
3307 }
3308
3309 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 4);
3310 }
3311
3312 break;
3313
3314 case mfHOOKSHOT:
3315
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3316 {
3317 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sHOOKSHOT],tmpscr->secretcset[sHOOKSHOT]);
3318 }
3319 else
3320 {
3321 17 tempitem=getItemID(itemsbuf,itype_hookshot,1);
3322
3323
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3324
3325
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3326
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3327 {
3328 12 tempitemx=x;
3329 12 tempitemy=y;
3330 12 }
3331
3332 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3333 }
3334
3335 17 break;
3336
3337 case mfWAND:
3338
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(!hints)
3339 {
3340 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sWAND],tmpscr->secretcset[sWAND]);
3341 }
3342 else
3343 {
3344 35 tempitem=getItemID(itemsbuf,itype_wand,1);
3345
3346
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(tempitem<0) break;
3347
3348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3349
3/6
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3350 {
3351 28 tempitemx=x;
3352 28 tempitemy=y;
3353 28 }
3354
3355 35 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3356 }
3357
3358 35 break;
3359
3360 case mfHAMMER:
3361
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3362 {
3363 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,tmpscr->secretcombo[sHAMMER],tmpscr->secretcset[sHAMMER]);
3364 }
3365 else
3366 {
3367 17 tempitem=getItemID(itemsbuf,itype_hammer,1);
3368
3369
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3370
3371
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3372
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3373 {
3374 13 tempitemx=x;
3375 13 tempitemy=y;
3376 13 }
3377
3378 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3379 }
3380
3381 17 break;
3382
3383 case mfARMOS_ITEM:
3384 case mfDIVE_ITEM:
3385
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
✓ Branch 2 taken 2602 times.
✗ Branch 3 not taken.
2602 if((!getmapflag() || (tmpscr->flags9&fBELOWRETURN)) && !(itemsbuf[Hero.getLastLensID()].flags & item_flag3))
3386 {
3387 2602 putitem2(dest,x,y,tmpscr->catchall, lens_hint_item[tmpscr->catchall][0], lens_hint_item[tmpscr->catchall][1], 0);
3388 2602 }
3389 2602 break;
3390
3391 case 16:
3392 case 17:
3393 case 18:
3394 case 19:
3395 case 20:
3396 case 21:
3397 case 22:
3398 case 23:
3399 case 24:
3400 case 25:
3401 case 26:
3402 case 27:
3403 case 28:
3404 case 29:
3405 case 30:
3406 case 31:
3407
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 107890 times.
108898 if(!hints)
3408
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107890 times.
215780 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3409 107890 putcombo(dest,x,y,tmpscr->secretcombo[checkflag-16+4],tmpscr->secretcset[checkflag-16+4]);
3410
3411 108898 break;
3412 case mfSECRETSNEXT:
3413 if(!hints)
3414 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3415 putcombo(dest,x,y,tmpscr->data[i]+1,tmpscr->cset[i]);
3416
3417 break;
3418
3419 case mfSTRIKE:
3420
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3421 {
3422 906 goto special;
3423 }
3424 else
3425 {
3426 break;
3427 }
3428
3429 28750 default: goto special;
3430
3431 special:
3432
8/8
✓ Branch 0 taken 14732 times.
✓ Branch 1 taken 14924 times.
✓ Branch 2 taken 528 times.
✓ Branch 3 taken 14204 times.
✓ Branch 4 taken 496 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 6108 times.
✓ Branch 7 taken 8128 times.
29656 if(layer && ((checkflag!=mfRAFT && checkflag!=mfRAFT_BRANCH&& checkflag!=mfRAFT_BOUNCE) ||(itemsbuf[Hero.getLastLensID()].flags & item_flag4)))
3433 {
3434
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6604 times.
✓ Branch 2 taken 4954 times.
✓ Branch 3 taken 1650 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1650 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6604 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate)) || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3435 {
3436 4954 rectfill(dest,x,y,x+15,y+15,WHITE);
3437 4954 }
3438 6604 }
3439
3440 29656 break;
3441 }
3442 7043520 }
3443 3521760 }
3444
3445
2/2
✓ Branch 0 taken 10005 times.
✓ Branch 1 taken 10005 times.
20010 if(layer)
3446 {
3447
2/2
✓ Branch 0 taken 9646 times.
✓ Branch 1 taken 359 times.
10005 if(tmpscr->door[0]==dWALK)
3448 359 rectfill(dest, 120, 16+playing_field_offset, 135, 31+playing_field_offset, WHITE);
3449
3450
2/2
✓ Branch 0 taken 9582 times.
✓ Branch 1 taken 423 times.
10005 if(tmpscr->door[1]==dWALK)
3451 423 rectfill(dest, 120, 144+playing_field_offset, 135, 159+playing_field_offset, WHITE);
3452
3453
2/2
✓ Branch 0 taken 9423 times.
✓ Branch 1 taken 582 times.
10005 if(tmpscr->door[2]==dWALK)
3454 582 rectfill(dest, 16, 80+playing_field_offset, 31, 95+playing_field_offset, WHITE);
3455
3456
2/2
✓ Branch 0 taken 9381 times.
✓ Branch 1 taken 624 times.
10005 if(tmpscr->door[3]==dWALK)
3457 624 rectfill(dest, 224, 80+playing_field_offset, 239, 95+playing_field_offset, WHITE);
3458
3459
2/2
✓ Branch 0 taken 9962 times.
✓ Branch 1 taken 43 times.
10005 if(tmpscr->door[0]==dBOMB)
3460 {
3461 43 showbombeddoor(dest, 0);
3462 43 }
3463
3464
2/2
✓ Branch 0 taken 9966 times.
✓ Branch 1 taken 39 times.
10005 if(tmpscr->door[1]==dBOMB)
3465 {
3466 39 showbombeddoor(dest, 1);
3467 39 }
3468
3469
2/2
✓ Branch 0 taken 9999 times.
✓ Branch 1 taken 6 times.
10005 if(tmpscr->door[2]==dBOMB)
3470 {
3471 6 showbombeddoor(dest, 2);
3472 6 }
3473
3474
2/2
✓ Branch 0 taken 9968 times.
✓ Branch 1 taken 37 times.
10005 if(tmpscr->door[3]==dBOMB)
3475 {
3476 37 showbombeddoor(dest, 3);
3477 37 }
3478 10005 }
3479
3480
2/2
✓ Branch 0 taken 17976 times.
✓ Branch 1 taken 2034 times.
20010 if(tmpscr->stairx + tmpscr->stairy)
3481 {
3482
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 1123 times.
2034 if(!hints)
3483 {
3484
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1123 times.
1123 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3485 1123 putcombo(dest,tmpscr->stairx,tmpscr->stairy+playing_field_offset,tmpscr->secretcombo[sSTAIRS],tmpscr->secretcset[sSTAIRS]);
3486 1123 }
3487 else
3488 {
3489
2/2
✓ Branch 0 taken 863 times.
✓ Branch 1 taken 48 times.
911 if(tmpscr->flags&fWHISTLE)
3490 {
3491 48 tempitem=getItemID(itemsbuf,itype_whistle,1);
3492 48 int32_t tempitemx=-16;
3493 48 int32_t tempitemy=-16;
3494
3495
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&(blink_rate/4)))
3496
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&(blink_rate/4))))
3497 {
3498 24 tempitemx=tmpscr->stairx;
3499 24 tempitemy=tmpscr->stairy+playing_field_offset;
3500 24 }
3501
3502 48 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3503 48 }
3504 }
3505 2034 }
3506 }
3507 20010 }
3508
3509 BITMAP *lens_scr_d; // The "d" is for "destructible"!
3510
3511 9666 void draw_lens_over()
3512 {
3513 // Oh, what the heck.
3514 static BITMAP *lens_scr = NULL;
3515 static int32_t last_width = -1;
3516 9666 int32_t width = itemsbuf[current_item_id(itype_lens,true)].misc1;
3517
3518 // Only redraw the circle if the size has changed
3519
2/2
✓ Branch 0 taken 9647 times.
✓ Branch 1 taken 19 times.
9666 if(width != last_width)
3520 {
3521
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 2 times.
19 if(lens_scr == NULL)
3522 {
3523 17 lens_scr = create_bitmap_ex(8,2*288,2*(240-playing_field_offset));
3524 17 }
3525
3526 19 clear_to_color(lens_scr, BLACK);
3527 19 circlefill(lens_scr, 288, 240-playing_field_offset, width, 0);
3528 19 circle(lens_scr, 288, 240-playing_field_offset, width+2, 0);
3529 19 circle(lens_scr, 288, 240-playing_field_offset, width+5, 0);
3530 19 last_width=width;
3531 19 }
3532
3533 9666 masked_blit(lens_scr, framebuf, 288-(HeroX()+8), 240-playing_field_offset-(HeroY()+8), 0, playing_field_offset, 256, 168);
3534 9666 do_primitives(framebuf, SPLAYER_LENS_OVER, tmpscr, 0, playing_field_offset);
3535 9666 }
3536
3537 //----------------------------------------------------------------
3538
3539 31797 void draw_wavy(BITMAP *source, BITMAP *target, int32_t amplitude, bool interpol)
3540 {
3541 //recreating a big bitmap every frame is highly sluggish.
3542
4/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 31792 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
31797 static BITMAP *wavebuf = create_bitmap_ex(8,288,240-original_playing_field_offset);
3543 31797 clear_to_color(wavebuf, BLACK);
3544 31797 blit(source,wavebuf,0,original_playing_field_offset,16,0,256,224-original_playing_field_offset);
3545
3546 int32_t ofs;
3547
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31797 times.
31797 amplitude = zc_min(2048,amplitude); // some arbitrary limit to prevent crashing
3548
4/6
✓ Branch 0 taken 31797 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31797 times.
✓ Branch 4 taken 494 times.
✓ Branch 5 taken 31303 times.
31797 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY)) amplitude = zc_min(16,amplitude);
3549 31797 int32_t amp2=168;
3550
2/4
✓ Branch 0 taken 31797 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31797 times.
31797 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY_2)) amp2*=2;
3551 31797 int32_t i=frame%amp2;
3552
3553
2/2
✓ Branch 0 taken 5341896 times.
✓ Branch 1 taken 31797 times.
5373693 for(int32_t j=0; j<168; j++)
3554 {
3555
3/4
✓ Branch 0 taken 2670948 times.
✓ Branch 1 taken 2670948 times.
✓ Branch 2 taken 2670948 times.
✗ Branch 3 not taken.
5341896 if(j&1 && interpol)
3556 {
3557 // Add 288*2048 to ensure it's never negative. It'll get modded out.
3558 ofs=288*2048+int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3559 }
3560 else
3561 {
3562 5341896 ofs=288*2048-int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3563 }
3564
3565
1/2
✓ Branch 0 taken 5341896 times.
✗ Branch 1 not taken.
5341896 if(ofs)
3566 {
3567
2/2
✓ Branch 0 taken 1367525376 times.
✓ Branch 1 taken 5341896 times.
1372867272 for(int32_t k=0; k<256; k++)
3568 {
3569 1367525376 target->line[j+original_playing_field_offset][k]=wavebuf->line[j][(k+ofs+16)%288];
3570 1367525376 }
3571 5341896 }
3572 5341896 }
3573 31797 }
3574
3575 28224 void draw_fuzzy(int32_t fuzz)
3576 // draws from right half of scrollbuf to framebuf
3577 {
3578 int32_t firstx, firsty, xstep, ystep, i, y, dx, dy;
3579 byte *start, *si, *di;
3580
3581
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28224 times.
28224 if(fuzz<1)
3582 fuzz = 1;
3583
3584 28224 xstep = 128%fuzz;
3585
3586
2/2
✓ Branch 0 taken 5880 times.
✓ Branch 1 taken 22344 times.
28224 if(xstep > 0)
3587 22344 xstep = fuzz-xstep;
3588
3589 28224 ystep = 112%fuzz;
3590
3591
2/2
✓ Branch 0 taken 8232 times.
✓ Branch 1 taken 19992 times.
28224 if(ystep > 0)
3592 19992 ystep = fuzz-ystep;
3593
3594 28224 firsty = 1;
3595
3596
2/2
✓ Branch 0 taken 28224 times.
✓ Branch 1 taken 1018416 times.
1046640 for(y=0; y<224;)
3597 {
3598 1018416 start = &(scrollbuf->line[y][256]);
3599
3600
4/4
✓ Branch 0 taken 1004304 times.
✓ Branch 1 taken 6336288 times.
✓ Branch 2 taken 6322176 times.
✓ Branch 3 taken 1018416 times.
7340592 for(dy=0; dy<ystep && dy+y<224; dy++)
3601 {
3602 6322176 si = start;
3603 6322176 di = &(framebuf->line[y+dy][0]);
3604 6322176 i = xstep;
3605 6322176 firstx = 1;
3606
3607
2/2
✓ Branch 0 taken 1618477056 times.
✓ Branch 1 taken 6322176 times.
1624799232 for(dx=0; dx<256; dx++)
3608 {
3609 1618477056 *(di++) = *si;
3610
3611
2/2
✓ Branch 0 taken 1363746048 times.
✓ Branch 1 taken 254731008 times.
1618477056 if(++i >= fuzz)
3612 {
3613
2/2
✓ Branch 0 taken 248408832 times.
✓ Branch 1 taken 6322176 times.
254731008 if(!firstx)
3614 248408832 si += fuzz;
3615 else
3616 {
3617 6322176 si += fuzz-xstep;
3618 6322176 firstx = 0;
3619 }
3620
3621 254731008 i = 0;
3622 254731008 }
3623 1618477056 }
3624 6322176 }
3625
3626
2/2
✓ Branch 0 taken 990192 times.
✓ Branch 1 taken 28224 times.
1018416 if(!firsty)
3627 990192 y += fuzz;
3628 else
3629 {
3630 28224 y += ystep;
3631 28224 ystep = fuzz;
3632 28224 firsty = 0;
3633 }
3634 }
3635 28224 }
3636
3637 18319686 void updatescr(bool allowwavy)
3638 {
3639
4/6
✓ Branch 0 taken 246 times.
✓ Branch 1 taken 18319440 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 246 times.
✓ Branch 4 taken 246 times.
✗ Branch 5 not taken.
18319686 static BITMAP *wavybuf = create_bitmap_ex(8,256,224);
3640
4/6
✓ Branch 0 taken 246 times.
✓ Branch 1 taken 18319440 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 246 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 246 times.
18319686 static BITMAP *panorama = create_bitmap_ex(8,256,224);
3641
3642
2/2
✓ Branch 0 taken 18292381 times.
✓ Branch 1 taken 27305 times.
18319686 if(toogam)
3643 {
3644 27305 textout_ex(framebuf,font,"no walls",8,216,1,-1);
3645 27305 }
3646
3647
1/2
✓ Branch 0 taken 18319686 times.
✗ Branch 1 not taken.
18319686 if(Showpal)
3648 dump_pal(framebuf);
3649
3650
2/2
✓ Branch 0 taken 17806540 times.
✓ Branch 1 taken 513146 times.
18319686 if(!Playing)
3651 513146 black_opening_count=0;
3652
3653
2/2
✓ Branch 0 taken 18156915 times.
✓ Branch 1 taken 162771 times.
18319686 if(black_opening_count<0) //shape is opening up
3654 {
3655 162771 black_opening(framebuf,black_opening_x,black_opening_y,(66+black_opening_count),66);
3656
3657
2/4
✓ Branch 0 taken 162771 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 162771 times.
162771 if(Advance||(!Paused))
3658 {
3659 162771 ++black_opening_count;
3660 162771 }
3661 162771 }
3662
2/2
✓ Branch 0 taken 18108933 times.
✓ Branch 1 taken 47982 times.
18156915 else if(black_opening_count>0) //shape is closing
3663 {
3664 47982 black_opening(framebuf,black_opening_x,black_opening_y,black_opening_count,66);
3665
3666
2/4
✓ Branch 0 taken 47982 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 47982 times.
47982 if(Advance||(!Paused))
3667 {
3668 47982 --black_opening_count;
3669 47982 }
3670 47982 }
3671
3672
3/4
✓ Branch 0 taken 18112126 times.
✓ Branch 1 taken 207560 times.
✓ Branch 2 taken 18112126 times.
✗ Branch 3 not taken.
18319686 if(black_opening_count==0&&black_opening_shape==bosFADEBLACK)
3673 {
3674 black_opening_shape = bosCIRCLE;
3675 memcpy(RAMpal, tempblackpal, PAL_SIZE*sizeof(RGB));
3676 refreshTints();
3677 refreshpal=true;
3678 }
3679
3680
2/2
✓ Branch 0 taken 17690872 times.
✓ Branch 1 taken 628814 times.
18319686 if(refreshpal)
3681 {
3682 628814 refreshpal=false;
3683 628814 RAMpal[253] = _RGB(0,0,0);
3684 628814 RAMpal[254] = _RGB(255,255,255);
3685 628814 hw_palette = &RAMpal;
3686 628814 update_hw_pal = true;
3687
3688 // Creating rgb_table and trans_table is pretty expensive, so try not to redo the same work
3689 // within a short period of time by using a cache.
3690 typedef std::array<uint32_t, PAL_SIZE> pal_table_cache_key;
3691 struct pal_table_cache_entry {
3692 RGB_MAP rgb_table;
3693 COLOR_MAP trans_table;
3694 };
3695
3/4
✓ Branch 0 taken 246 times.
✓ Branch 1 taken 628568 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 246 times.
628814 static std::map<pal_table_cache_key, pal_table_cache_entry> pal_table_cache;
3696
3697 static constexpr int pal_table_cache_max_memory_mb = 10;
3698 static constexpr int pal_table_cache_max_size = pal_table_cache_max_memory_mb / ((double)sizeof(pal_table_cache_entry) / 1024 / 1024);
3699
2/2
✓ Branch 0 taken 628649 times.
✓ Branch 1 taken 165 times.
628814 if (pal_table_cache.size() > pal_table_cache_max_size)
3700 165 pal_table_cache.clear();
3701
3702 pal_table_cache_key key;
3703
2/2
✓ Branch 0 taken 160976384 times.
✓ Branch 1 taken 628814 times.
161605198 for (int i = 0; i < PAL_SIZE; i++)
3704 160976384 key[i] = RAMpal[i].r + (RAMpal[i].g << 8) + (RAMpal[i].b << 16);
3705 628814 auto cache_it = pal_table_cache.find(key);
3706
2/2
✓ Branch 0 taken 24956 times.
✓ Branch 1 taken 603858 times.
628814 if (cache_it == pal_table_cache.end())
3707 {
3708 24956 create_rgb_table(&rgb_table, RAMpal, NULL);
3709 24956 create_zc_trans_table(&trans_table, RAMpal, 128, 128, 128);
3710 24956 pal_table_cache[key] = {rgb_table, trans_table};
3711 24956 trans_table2 = trans_table;
3712 24956 }
3713 else
3714 {
3715 603858 rgb_table = cache_it->second.rgb_table;
3716 603858 trans_table = cache_it->second.trans_table;
3717 603858 trans_table2 = cache_it->second.trans_table;
3718 }
3719
3720
2/2
✓ Branch 0 taken 160976384 times.
✓ Branch 1 taken 628814 times.
161605198 for(int32_t q=0; q<PAL_SIZE; q++)
3721 {
3722 160976384 trans_table2.data[0][q] = q;
3723 160976384 trans_table2.data[q][q] = q;
3724 160976384 }
3725 628814 }
3726
3727 18319686 bool clearwavy = (wavy <= 0);
3728
3729
2/2
✓ Branch 0 taken 8341 times.
✓ Branch 1 taken 18311345 times.
18319686 if(wavy <= 0)
3730 {
3731 // So far one thing can alter wavy apart from scripts: Wavy DMaps.
3732 18311345 wavy = (DMaps[currdmap].flags&dmfWAVY ? 4 : 0);
3733 18311345 }
3734
3735 18319686 blit(framebuf, wavybuf, 0, 0, 0, 0, 256, 224);
3736
3737
6/6
✓ Branch 0 taken 32047 times.
✓ Branch 1 taken 18287639 times.
✓ Branch 2 taken 31925 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 31797 times.
18319686 if(wavy && Playing && allowwavy)
3738 {
3739 31797 draw_wavy(framebuf, wavybuf, wavy,false);
3740 31797 }
3741
3742
2/2
✓ Branch 0 taken 18311345 times.
✓ Branch 1 taken 8341 times.
18319686 if(clearwavy)
3743 18311345 wavy = 0; // Wavy was set by a DMap flag. Clear it.
3744
2/4
✓ Branch 0 taken 8341 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8341 times.
8341 else if(Playing && !Paused)
3745 8341 wavy--; // Wavy was set by a script. Decrement it.
3746
3747
5/6
✓ Branch 0 taken 17806540 times.
✓ Branch 1 taken 513146 times.
✓ Branch 2 taken 672020 times.
✓ Branch 3 taken 17134520 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 672020 times.
18319686 if(Playing && msgpos && !screenscrolling)
3748 {
3749
1/2
✓ Branch 0 taken 672020 times.
✗ Branch 1 not taken.
672020 if(!(msg_bg_display_buf->clip))
3750 672020 blit_msgstr_bg(framebuf,0,0,0,playing_field_offset,256,168);
3751
1/2
✓ Branch 0 taken 672020 times.
✗ Branch 1 not taken.
672020 if(!(msg_portrait_display_buf->clip))
3752 672020 blit_msgstr_prt(framebuf,0,0,0,playing_field_offset,256,168);
3753
1/2
✓ Branch 0 taken 672020 times.
✗ Branch 1 not taken.
672020 if(!(msg_txt_display_buf->clip))
3754 672020 blit_msgstr_fg(framebuf,0,0,0,playing_field_offset,256,168);
3755 672020 }
3756
3757
2/2
✓ Branch 0 taken 18129501 times.
✓ Branch 1 taken 190185 times.
18319686 bool nosubscr = (tmpscr->flags3&fNOSUBSCR && !(tmpscr->flags3&fNOSUBSCROFFSET));
3758
3759
2/2
✓ Branch 0 taken 18134774 times.
✓ Branch 1 taken 184912 times.
18319686 if(nosubscr)
3760 {
3761 184912 rectfill(panorama,0,0,255,passive_subscreen_height/2,0);
3762 184912 rectfill(panorama,0,168+passive_subscreen_height/2,255,168+passive_subscreen_height-1,0);
3763 184912 blit(wavybuf,panorama,0,playing_field_offset,0,passive_subscreen_height/2,256,224-passive_subscreen_height);
3764 184912 }
3765
3766 //TODO: Optimize blit 'overcalls' -Gleeok
3767
2/2
✓ Branch 0 taken 184912 times.
✓ Branch 1 taken 18134774 times.
18319686 BITMAP *source = nosubscr ? panorama : wavybuf;
3768 18319686 blit(source,framebuf,0,0,0,0,256,224);
3769
3770 18319686 update_hw_screen();
3771 18319686 }
3772
3773 //----------------------------------------------------------------
3774
3775 static PALETTE syspal;
3776 int32_t onGUISnapshot()
3777 {
3778 char buf[200];
3779 int32_t num=0;
3780 do
3781 {
3782 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3783 }
3784 while(num<99999 && exists(buf));
3785
3786 if (!al_save_bitmap(buf, al_get_backbuffer(all_get_display())))
3787 InfoDialog("Error", "Failed to save snapshot").show();
3788
3789 return D_O_K;
3790 }
3791
3792 int32_t onNonGUISnapshot()
3793 {
3794 PALETTE temppal;
3795 get_palette(temppal);
3796 bool realpal=(zc_getkey(KEY_ZC_LCONTROL, true) || zc_getkey(KEY_ZC_RCONTROL, true));
3797
3798 char buf[200];
3799 int32_t num=0;
3800
3801 do
3802 {
3803 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3804 }
3805 while(num<99999 && exists(buf));
3806
3807 if ((tmpscr->flags3&fNOSUBSCR && !(tmpscr->flags3&fNOSUBSCROFFSET)) && !(key[KEY_ALT]))
3808 {
3809 BITMAP *b = create_bitmap_ex(8,256,168);
3810 clear_to_color(b,0);
3811 blit(framebuf,b,0,passive_subscreen_height/2,0,0,256,168);
3812 alleg4_save_bitmap(b, SnapshotScale, buf, realpal ? temppal : RAMpal);
3813 destroy_bitmap(b);
3814 }
3815 else
3816 {
3817 alleg4_save_bitmap(framebuf, SnapshotScale, buf, realpal?temppal:RAMpal);
3818 }
3819
3820 return D_O_K;
3821 }
3822
3823 int32_t onSnapshot()
3824 {
3825 if(zc_getkey(KEY_LSHIFT, true)||zc_getkey(KEY_RSHIFT, true))
3826 {
3827 onGUISnapshot();
3828 }
3829 else
3830 {
3831 onNonGUISnapshot();
3832 }
3833
3834 return D_O_K;
3835 }
3836
3837 int32_t onSaveMapPic()
3838 {
3839 int32_t mapres2 = 0;
3840 char buf[200];
3841 int32_t num=0;
3842 mapscr tmpscr_b[2];
3843 mapscr tmpscr_c[6];
3844 BITMAP* _screen_draw_buffer = NULL;
3845 _screen_draw_buffer = create_bitmap_ex(8,256,224);
3846 set_clip_state(_screen_draw_buffer,1);
3847
3848 for(int32_t i=0; i<6; ++i)
3849 {
3850 tmpscr_c[i] = tmpscr2[i];
3851 tmpscr2[i].zero_memory();
3852
3853 if(i>=2)
3854 {
3855 continue;
3856 }
3857
3858 tmpscr_b[i] = tmpscr[i];
3859 tmpscr[i].zero_memory();
3860 }
3861
3862 do
3863 {
3864 sprintf(buf, "%szc_screen%05d.png", get_snap_str(), ++num);
3865 }
3866 while(num<99999 && exists(buf));
3867
3868 BITMAP* mappic = NULL;
3869
3870
3871 bool done=false, redraw=true;
3872
3873 mappic = create_bitmap_ex(8,(256*16)>>mapres,(176*8)>>mapres);
3874
3875 if(!mappic)
3876 {
3877 enter_sys_pal();
3878 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
3879 exit_sys_pal();
3880 return D_O_K;;
3881 }
3882
3883 // draw the map
3884 set_clip_rect(_screen_draw_buffer, 0, 0, _screen_draw_buffer->w, _screen_draw_buffer->h);
3885
3886 for(int32_t y=0; y<8; y++)
3887 {
3888 for(int32_t x=0; x<16; x++)
3889 {
3890 if(!displayOnMap(x, y))
3891 {
3892 rectfill(_screen_draw_buffer, 0, 0, 255, 223, WHITE);
3893 }
3894 else
3895 {
3896 int32_t s = (y<<4) + x;
3897 loadscr2(1,s,-1);
3898
3899 if(XOR((tmpscr+1)->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_layer(_screen_draw_buffer, 0, 2, tmpscr+1, -256, playing_field_offset, 2);
3900
3901 if(XOR((tmpscr+1)->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_layer(_screen_draw_buffer, 0, 3, tmpscr+1, -256, playing_field_offset, 2);
3902
3903 if(lenscheck(tmpscr+1,0)) putscr(_screen_draw_buffer,256,0,tmpscr+1);
3904 do_layer(_screen_draw_buffer, 0, 1, tmpscr+1, -256, playing_field_offset, 2);
3905
3906 if(!XOR((tmpscr+1)->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_layer(_screen_draw_buffer, 0, 2, tmpscr+1, -256, playing_field_offset, 2);
3907
3908 putscrdoors(_screen_draw_buffer,256,0,tmpscr+1);
3909 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
3910 {
3911 do_layer(_screen_draw_buffer, -2, 0, tmpscr+1, -256, playing_field_offset, 2);
3912 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
3913 {
3914 do_layer(_screen_draw_buffer, -2, 1, tmpscr+1, -256, playing_field_offset, 2);
3915 do_layer(_screen_draw_buffer, -2, 2, tmpscr+1, -256, playing_field_offset, 2);
3916 }
3917 }
3918 do_layer(_screen_draw_buffer, -3, 0, tmpscr+1, -256, playing_field_offset, 2); // Freeform combos!
3919
3920 if(!XOR((tmpscr+1)->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_layer(_screen_draw_buffer, 0, 3, tmpscr+1, -256, playing_field_offset, 2);
3921
3922 do_layer(_screen_draw_buffer, 0, 4, tmpscr+1, -256, playing_field_offset, 2);
3923 do_layer(_screen_draw_buffer, -1, 0, tmpscr+1, -256, playing_field_offset, 2);
3924 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3925 {
3926 do_layer(_screen_draw_buffer, -1, 1, tmpscr+1, -256, playing_field_offset, 2);
3927 do_layer(_screen_draw_buffer, -1, 2, tmpscr+1, -256, playing_field_offset, 2);
3928 }
3929 do_layer(_screen_draw_buffer, 0, 5, tmpscr+1, -256, playing_field_offset, 2);
3930 do_layer(_screen_draw_buffer, 0, 6, tmpscr+1, -256, playing_field_offset, 2);
3931
3932 }
3933
3934 stretch_blit(_screen_draw_buffer, mappic, 256, 0, 256, 176, x<<(8-mapres), (y*176)>>mapres, 256>>mapres, 176>>mapres);
3935 }
3936 }
3937
3938 for(int32_t i=0; i<6; ++i)
3939 {
3940 tmpscr2[i]=tmpscr_c[i];
3941
3942 if(i>=2)
3943 {
3944 continue;
3945 }
3946
3947 tmpscr[i]=tmpscr_b[i];
3948 }
3949
3950 save_bitmap(buf,mappic,RAMpal);
3951 destroy_bitmap(mappic);
3952 destroy_bitmap(_screen_draw_buffer);
3953 return D_O_K;
3954 }
3955
3956 55 void f_Quit(int32_t type)
3957 {
3958
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 if(type==qQUIT && !Playing)
3959 return;
3960
3961 55 bool from_menu = is_sys_pal;
3962
3963
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(!from_menu)
3964 {
3965 55 music_pause();
3966 55 pause_all_sfx();
3967 55 sys_mouse();
3968 55 }
3969 55 enter_sys_pal();
3970 55 clear_keybuf();
3971
3972
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 13 times.
55 if (replay_version_check(0, 10))
3973 13 replay_poll();
3974
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if (replay_is_replaying())
3975 55 replay_peek_quit();
3976
3977
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 if (!replay_is_replaying())
3978 switch(type)
3979 {
3980 case qQUIT:
3981 onQuit();
3982 break;
3983
3984 case qRESET:
3985 onReset();
3986 break;
3987
3988 case qEXIT:
3989 onExit();
3990 break;
3991 }
3992
3993
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 if(Quit)
3994 {
3995 55 kill_sfx();
3996 55 music_stop();
3997 55 exit_sys_pal();
3998 55 update_hw_screen();
3999 55 }
4000 else
4001 {
4002 exit_sys_pal();
4003 if(!from_menu)
4004 {
4005 music_resume();
4006 resume_all_sfx();
4007 }
4008 }
4009
4010
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(!from_menu)
4011 55 game_mouse();
4012 55 eat_buttons();
4013
4014 55 zc_readrawkey(KEY_ESC);
4015
4016 55 zc_readrawkey(KEY_ENTER);
4017 55 }
4018
4019 //----------------------------------------------------------------
4020
4021 int32_t onNoWalls()
4022 {
4023 cheats_enqueue(Cheat::Walls);
4024 return D_O_K;
4025 }
4026
4027 int32_t onIgnoreSideview()
4028 {
4029 cheats_enqueue(Cheat::IgnoreSideView);
4030 return D_O_K;
4031 }
4032
4033 18318343 int32_t input_idle(bool checkmouse)
4034 {
4035 static int32_t mx, my, mz, mb;
4036
4037
4/6
✓ Branch 0 taken 18318343 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4911060 times.
✓ Branch 3 taken 13407283 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4911060 times.
23229403 if(keypressed() || zc_key_pressed() ||
4038
4/8
✓ Branch 0 taken 4911060 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4911060 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4911060 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4911060 times.
✗ Branch 7 not taken.
4911060 (checkmouse && (mx != mouse_x || my != mouse_y || mz != mouse_z || mb != mouse_b)))
4039 {
4040 13407283 idle_count = 0;
4041
4042
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13407283 times.
13407283 if(active_count < MAX_ACTIVE)
4043 {
4044 13407283 ++active_count;
4045 13407283 }
4046 13407283 }
4047
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4911060 times.
4911060 else if(idle_count < MAX_IDLE)
4048 {
4049 4911060 ++idle_count;
4050 4911060 active_count = 0;
4051 4911060 }
4052
4053 18318343 mx = mouse_x;
4054 18318343 my = mouse_y;
4055 18318343 mz = mouse_z;
4056 18318343 mb = mouse_b;
4057
4058 18318343 return idle_count;
4059 }
4060
4061 int32_t onGoFast()
4062 {
4063 cheats_enqueue(Cheat::Fast);
4064 return D_O_K;
4065 }
4066
4067 int32_t onKillCheat()
4068 {
4069 cheats_enqueue(Cheat::Kill);
4070 return D_O_K;
4071 }
4072
4073 int32_t onSecretsCheat()
4074 {
4075 cheats_enqueue(Cheat::TrigSecrets);
4076 return D_O_K;
4077 }
4078 int32_t onSecretsCheatPerm()
4079 {
4080 cheats_enqueue(Cheat::TrigSecretsPerm);
4081 return D_O_K;
4082 }
4083
4084 int32_t onShowLayer0()
4085 {
4086 show_layer_0 = !show_layer_0;
4087 return D_O_K;
4088 }
4089 int32_t onShowLayer1()
4090 {
4091 show_layer_1 = !show_layer_1;
4092 return D_O_K;
4093 }
4094 int32_t onShowLayer2()
4095 {
4096 show_layer_2 = !show_layer_2;
4097 return D_O_K;
4098 }
4099 int32_t onShowLayer3()
4100 {
4101 show_layer_3 = !show_layer_3;
4102 return D_O_K;
4103 }
4104 int32_t onShowLayer4()
4105 {
4106 show_layer_4 = !show_layer_4;
4107 return D_O_K;
4108 }
4109 int32_t onShowLayer5()
4110 {
4111 show_layer_5 = !show_layer_5;
4112 return D_O_K;
4113 }
4114 int32_t onShowLayer6()
4115 {
4116 show_layer_6 = !show_layer_6;
4117 return D_O_K;
4118 }
4119 int32_t onShowLayerO()
4120 {
4121 show_layer_over=!show_layer_over;
4122 return D_O_K;
4123 }
4124 int32_t onShowLayerP()
4125 {
4126 show_layer_push=!show_layer_push;
4127 return D_O_K;
4128 }
4129 int32_t onShowLayerS()
4130 {
4131 show_sprites=!show_sprites;
4132 return D_O_K;
4133 }
4134 int32_t onShowLayerF()
4135 {
4136 show_ffcs=!show_ffcs;
4137 return D_O_K;
4138 }
4139 int32_t onShowLayerW()
4140 {
4141 show_walkflags=!show_walkflags;
4142 if(show_walkflags)
4143 show_effectflags = false;
4144 return D_O_K;
4145 }
4146 int32_t onShowLayerE()
4147 {
4148 show_effectflags=!show_effectflags;
4149 if(show_effectflags)
4150 show_walkflags = false;
4151 return D_O_K;
4152 }
4153 int32_t onShowFFScripts()
4154 {
4155 show_ff_scripts=!show_ff_scripts;
4156 return D_O_K;
4157 }
4158 int32_t onShowHitboxes()
4159 {
4160 show_hitboxes=!show_hitboxes;
4161 return D_O_K;
4162 }
4163 int32_t onShowInfoOpacity()
4164 {
4165 info_opacity = vbound(getnumber("Debug Info Opacity",info_opacity),0,255);
4166 zc_set_config("zc","debug_info_opacity",info_opacity);
4167 return D_O_K;
4168 }
4169
4170 int32_t onLightSwitch()
4171 {
4172 cheats_enqueue(Cheat::Light);
4173 return D_O_K;
4174 }
4175
4176 int32_t onGoTo();
4177 int32_t onGoToComplete();
4178
4179 18318343 bool handle_close_btn_quit()
4180 {
4181
1/2
✓ Branch 0 taken 18318343 times.
✗ Branch 1 not taken.
18318343 if(close_button_quit)
4182 {
4183 close_button_quit=false;
4184 f_Quit(qEXIT);
4185 }
4186 18318343 return (exiting_program = Quit==qEXIT);
4187 }
4188
4189 18318343 void syskeys()
4190 {
4191 18318343 update_system_keys();
4192
4193 int32_t oldtitle_version;
4194
4195 18318343 poll_joystick();
4196
4197 18318343 handle_close_btn_quit();
4198
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18318343 times.
18318343 if(Quit == qEXIT) return;
4199
4200
2/10
✓ Branch 0 taken 18318343 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18318343 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
18318343 if(rMbtn() || (gui_mouse_b() && !mouse_down && ClickToFreeze &&!disableClickToFreeze))
4201 {
4202 System();
4203 }
4204
4205 18318343 mouse_down=gui_mouse_b();
4206
4207
1/2
✓ Branch 0 taken 18318343 times.
✗ Branch 1 not taken.
18318343 if(zc_read_system_key(KEY_F1))
4208 {
4209 if(zc_get_system_key(KEY_ZC_LCONTROL) || zc_get_system_key(KEY_ZC_RCONTROL))
4210 {
4211 halt=!halt;
4212 //zinit.subscreen=(zinit.subscreen+1)%ssdtMAX;
4213 }
4214 else
4215 {
4216 Throttlefps=!Throttlefps;
4217 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4218 }
4219 }
4220
4221
1/2
✓ Branch 0 taken 18318343 times.
✗ Branch 1 not taken.
18318343 if(zc_read_system_key(KEY_F2))
4222 {
4223 ShowFPS=!ShowFPS;
4224 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
4225 }
4226
4227
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18318343 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18318343 if(zc_read_system_key(KEY_F3) && Playing) Paused=!Paused;
4228
4229
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18318343 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18318343 if(zc_read_system_key(KEY_F4) && Playing)
4230 {
4231 Paused=true;
4232 Advance=true;
4233 }
4234
4235
1/2
✓ Branch 0 taken 18318343 times.
✗ Branch 1 not taken.
18318343 if(zc_read_system_key(KEY_F6)) onTryQuit();
4236
4237 #ifndef ALLEGRO_MACOSX
4238
1/2
✓ Branch 0 taken 18318343 times.
✗ Branch 1 not taken.
18318343 if(zc_read_system_key(KEY_F9)) f_Quit(qRESET);
4239
4240
1/2
✓ Branch 0 taken 18318343 times.
✗ Branch 1 not taken.
18318343 if(zc_read_system_key(KEY_F10)) f_Quit(qEXIT);
4241 #else
4242 if(zc_read_system_key(KEY_F7)) f_Quit(qRESET);
4243
4244 if(zc_read_system_key(KEY_F8)) f_Quit(qEXIT);
4245 #endif
4246
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 18318343 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
18318343 if(zc_read_system_key(KEY_F5)&&(Playing && currscr<128 && DMaps[currdmap].flags&dmfVIEWMAP)) onSaveMapPic();
4247
4248
1/2
✓ Branch 0 taken 18318343 times.
✗ Branch 1 not taken.
18318343 if (zc_read_system_key(KEY_F12))
4249 {
4250 onSnapshot();
4251 }
4252
4253
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18318343 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18318343 if(debug_enabled && zc_read_system_key(KEY_TAB))
4254 set_debug(!get_debug());
4255
4256
1/2
✓ Branch 0 taken 18318343 times.
✗ Branch 1 not taken.
18318343 if(CheatModifierKeys())
4257 {
4258 for(Cheat c = (Cheat)1; c < Cheat::Last; c = (Cheat)(c+1))
4259 {
4260 if(!bindable_cheat(c))
4261 continue;
4262 if(get_debug() || cheat >= cheat_lvl(c))
4263 {
4264 if(checkcheat(c))
4265 cheats_hit_bind(c);
4266 }
4267 }
4268 }
4269
4270
1/2
✓ Branch 0 taken 18318343 times.
✗ Branch 1 not taken.
18318343 if(volkeys)
4271 {
4272 if(zc_read_system_key(KEY_PGUP)) master_volume(-1,midi_volume+8);
4273
4274 if(zc_read_system_key(KEY_PGDN)) master_volume(-1,midi_volume==255?248:midi_volume-8);
4275
4276 if(zc_read_system_key(KEY_HOME)) master_volume(digi_volume+8,-1);
4277
4278 if(zc_read_system_key(KEY_END)) master_volume(digi_volume==255?248:digi_volume-8,-1);
4279 }
4280
4281
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18318343 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
18318343 if(!get_debug() || !SystemKeys || replay_is_replaying())
4282 18318343 goto bottom;
4283
4284 if(zc_readkey(KEY_P)) Paused=!Paused;
4285
4286 if(zc_readkey(KEY_A))
4287 {
4288 Paused=true;
4289 Advance=true;
4290 }
4291
4292 if(zc_readkey(KEY_G)) db=(db==999)?0:999;
4293 #ifndef ALLEGRO_MACOSX
4294 if(zc_readkey(KEY_F8)) Showpal=!Showpal;
4295
4296 if(zc_readkey(KEY_F7))
4297 {
4298 Matrix(ss_speed, ss_density, 0);
4299 game_pal();
4300 }
4301 #else
4302 // The reason these are different on Mac in the first place is that
4303 // the OS doesn't let us use F9 and F10...
4304 if(zc_readkey(KEY_F10)) Showpal=!Showpal;
4305
4306 if(zc_readkey(KEY_F9))
4307 {
4308 Matrix(ss_speed, ss_density, 0);
4309 game_pal();
4310 }
4311 #endif
4312 if(zc_readkey(KEY_PLUS_PAD) || zc_readkey(KEY_EQUALS))
4313 {
4314 //change containers
4315 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4316 {
4317 //magic containers
4318 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4319 {
4320 game->set_maxmagic(zc_min(game->get_maxmagic()+game->get_mp_per_block(),game->get_mp_per_block()*8));
4321 }
4322 else
4323 {
4324 game->set_maxlife(zc_min(game->get_maxlife()+game->get_hp_per_heart(),game->get_hp_per_heart()*24));
4325 }
4326 }
4327 else
4328 {
4329 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4330 {
4331 game->set_magic(zc_min(game->get_magic()+1,game->get_maxmagic()));
4332 }
4333 else
4334 {
4335 game->set_life(zc_min(game->get_life()+1,game->get_maxlife()));
4336 }
4337 }
4338 }
4339
4340 if(zc_readkey(KEY_MINUS_PAD) || zc_readkey(KEY_MINUS))
4341 {
4342 //change containers
4343 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4344 {
4345 //magic containers
4346 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4347 {
4348 game->set_maxmagic(zc_max(game->get_maxmagic()-game->get_mp_per_block(),0));
4349 game->set_magic(zc_min(game->get_maxmagic(), game->get_magic()));
4350 //heart containers
4351 }
4352 else
4353 {
4354 game->set_maxlife(zc_max(game->get_maxlife()-game->get_hp_per_heart(),game->get_hp_per_heart()));
4355 game->set_life(zc_min(game->get_maxlife(), game->get_life()));
4356 }
4357 }
4358 else
4359 {
4360 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4361 {
4362 game->set_magic(zc_max(game->get_magic()-1,0));
4363 }
4364 else
4365 {
4366 game->set_life(zc_max(game->get_life()-1,0));
4367 }
4368 }
4369 }
4370
4371 if(zc_readkey(KEY_COMMA)) jukebox(currmidi-1);
4372
4373 if(zc_readkey(KEY_STOP)) jukebox(currmidi+1);
4374
4375 verifyBothWeapons();
4376
4377 bottom:
4378
4379
1/2
✓ Branch 0 taken 18318343 times.
✗ Branch 1 not taken.
18318343 if(input_idle(true) > after_time())
4380 {
4381 Matrix(ss_speed, ss_density, 0);
4382 game_pal();
4383 }
4384 18318343 }
4385
4386 1114675 void checkQuitKeys()
4387 {
4388 #ifndef ALLEGRO_MACOSX
4389
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1114675 times.
1114675 if(key[KEY_F9]) f_Quit(qRESET);
4390
4391
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1114675 times.
1114675 if(key[KEY_F10]) f_Quit(qEXIT);
4392 #else
4393 if(key[KEY_F7]) f_Quit(qRESET);
4394
4395 if(key[KEY_F8]) f_Quit(qEXIT);
4396 #endif
4397 1114675 }
4398
4399 18318543 bool CheatModifierKeys()
4400 {
4401 // Cheats are replayed via the X cheat step, no need to check for keyboard input
4402 // to trigger cheats.
4403
2/2
✓ Branch 0 taken 18318243 times.
✓ Branch 1 taken 300 times.
18318543 if (replay_is_replaying())
4404 18318243 return false;
4405
4406
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 200 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
300 if ( ( cheat_modifier_keys[0] > 0 && key[cheat_modifier_keys[0]] ) ||
4407
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 100 times.
200 ( cheat_modifier_keys[1] > 0 && key[cheat_modifier_keys[1]] ) ||
4408
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 (cheat_modifier_keys[0] <= 0 && cheat_modifier_keys[1] <= 0))
4409 {
4410
0/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
200 if ( ( cheat_modifier_keys[2] <= 0 || key[cheat_modifier_keys[2]] ) ||
4411 ( cheat_modifier_keys[3] > 0 && key[cheat_modifier_keys[3]] ) ||
4412 (cheat_modifier_keys[2] <= 0 && cheat_modifier_keys[3] <= 0))
4413 {
4414 return true;
4415 }
4416 }
4417 100 return false;
4418 18318343 }
4419
4420 //99:05:54, for some reason?
4421 #define OLDMAXTIME 21405240
4422 //9000:00:00, the highest even-thousand hour fitting within 32b signed. This is 375 *DAYS*.
4423 #define MAXTIME 1944000000
4424
4425 18319686 void advanceframe(bool allowwavy, bool sfxcleanup, bool allowF6Script)
4426 {
4427
1/2
✓ Branch 0 taken 18319686 times.
✗ Branch 1 not taken.
18319686 if(zcmusic!=NULL)
4428 {
4429 zcmusic_poll();
4430 }
4431 18319686 zcmixer_update(zcmixer, emusic_volume, FFCore.usr_music_volume, get_qr(qr_OLD_SCRIPT_VOLUME));
4432
4433 18319686 updatescr(allowwavy);
4434
4435 18319686 Advance=false;
4436
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18319686 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18319686 times.
18319686 while(Paused && !Advance && !Quit)
4437 {
4438 // have to call this, otherwise we'll get an infinite loop
4439 syskeys();
4440 if(allowF6Script)
4441 {
4442 FFCore.runF6Engine();
4443 }
4444
4445 #ifdef _WIN32
4446
4447 if(use_dwm_flush)
4448 {
4449 do_DwmFlush();
4450 }
4451
4452 #endif
4453
4454 // to keep music playing
4455 if(zcmusic!=NULL)
4456 {
4457 zcmusic_poll();
4458 }
4459
4460 update_hw_screen();
4461 }
4462
4463
2/2
✓ Branch 0 taken 18318377 times.
✓ Branch 1 taken 1309 times.
18319686 if(Quit)
4464 1309 return;
4465
4466
3/4
✓ Branch 0 taken 17805534 times.
✓ Branch 1 taken 512843 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17805534 times.
18318377 if(Playing && game->get_time()<unsigned(get_qr(qr_GREATER_MAX_TIME) ? MAXTIME : OLDMAXTIME))
4467 17805534 game->change_time(1);
4468
4469 // Many mistakes have been make re: inputs, and we are stuck with many replays relying on those mistakes.
4470
4471 18318377 bool should_reset_down_state = !get_qr(qr_BROKEN_INPUT_DOWN_STATE);
4472
2/2
✓ Branch 0 taken 8608763 times.
✓ Branch 1 taken 9709614 times.
18318377 if (replay_version_check(0, 16))
4473 9709614 should_reset_down_state = replay_version_check(11, 16);
4474
2/2
✓ Branch 0 taken 14985380 times.
✓ Branch 1 taken 3332997 times.
18318377 if (should_reset_down_state)
4475 {
4476
2/2
✓ Branch 0 taken 59993946 times.
✓ Branch 1 taken 3332997 times.
63326943 for (int i = 0; i < ZC_CONTROL_STATES; i++)
4477 59993946 down_control_states[i] = raw_control_state[i];
4478 3332997 }
4479
4480
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 18318343 times.
18318377 if (replay_is_active())
4481 {
4482
2/2
✓ Branch 0 taken 1545423 times.
✓ Branch 1 taken 16772920 times.
18318343 if (replay_version_check(3))
4483 16772920 replay_poll();
4484
4485
4/4
✓ Branch 0 taken 7388911 times.
✓ Branch 1 taken 10929432 times.
✓ Branch 2 taken 100535 times.
✓ Branch 3 taken 7288376 times.
18318343 if (replay_version_check(11) || replay_version_check(6, 8))
4486 11029967 replay_peek_input();
4487 18318343 }
4488
4489 18318377 load_control_called_this_frame = false;
4490
4491 18318377 poll_keyboard();
4492 18318377 update_keys();
4493
4494 18318377 ++frame;
4495
4496
2/2
✓ Branch 0 taken 134 times.
✓ Branch 1 taken 18318243 times.
18318377 if (replay_is_replaying())
4497 18318243 replay_do_cheats();
4498 18318377 syskeys();
4499
4500 // The mouse variables can change from the mouse thread at anytime during a frame,
4501 // so save the result at the start so that replaying is consistent.
4502 18318377 script_mouse_x = gui_mouse_x();
4503 18318377 script_mouse_y = gui_mouse_y();
4504 18318377 script_mouse_z = mouse_z;
4505 18318377 script_mouse_b = mouse_b;
4506
4507 // Cheats used via the System menu (called by syskeys) will call cheats_enqueue. syskeys
4508 // is called just above, and in the paused loop above, so the queue-and-defer-slightly
4509 // approach here means it doesn't matter which call adds the cheat.
4510 18318377 cheats_execute_queued();
4511
4512
2/2
✓ Branch 0 taken 134 times.
✓ Branch 1 taken 18318243 times.
18318377 if (replay_is_replaying())
4513 18318243 replay_peek_quit();
4514
2/2
✓ Branch 0 taken 18318322 times.
✓ Branch 1 taken 55 times.
18318377 if (GameFlags & GAMEFLAG_TRYQUIT)
4515 55 replay_step_quit(0);
4516
2/2
✓ Branch 0 taken 3319 times.
✓ Branch 1 taken 18315058 times.
18318377 if(allowF6Script)
4517 18315058 FFCore.runF6Engine();
4518
2/2
✓ Branch 0 taken 714 times.
✓ Branch 1 taken 18317663 times.
18318377 if (Quit)
4519 714 replay_step_quit(Quit);
4520
4521 #ifdef _WIN32
4522
4523 if(use_dwm_flush)
4524 {
4525 do_DwmFlush();
4526 }
4527
4528 #endif
4529
4530
2/2
✓ Branch 0 taken 208642 times.
✓ Branch 1 taken 18109735 times.
18318377 if(sfxcleanup)
4531 18109735 sfx_cleanup();
4532
4533 18318377 jit_poll();
4534
4535 #ifdef __EMSCRIPTEN__
4536 // Yield the main thread back to the browser occasionally.
4537 if (is_headless())
4538 {
4539 static int rate = 10000;
4540 static int force_yield = rate;
4541 if (force_yield++ >= rate)
4542 {
4543 force_yield = 0;
4544 emscripten_sleep(0);
4545 }
4546 }
4547 #endif
4548
4549
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 18318277 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
18318377 if (zqtesting_mode && test_mode_auto_restart)
4550 {
4551 static auto last_write_time = fs::last_write_time(qstpath);
4552 static auto last_check = std::chrono::system_clock::now();
4553
4554 if (std::chrono::system_clock::now() - last_check > 200ms)
4555 {
4556 last_check = std::chrono::system_clock::now();
4557 auto write_time = fs::last_write_time(qstpath);
4558 if (last_write_time != write_time)
4559 {
4560 last_write_time = write_time;
4561 disableClickToFreeze = false;
4562 Quit = qRESET;
4563 replay_quit();
4564 }
4565 }
4566 }
4567 18319686 }
4568
4569 589 void zapout()
4570 {
4571 589 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
4572 589 blit(framebuf,scrollbuf,0,0,256,0,256,224);
4573
4574 589 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4575 589 script_drawing_commands.Clear();
4576
4577 // zap out
4578
2/2
✓ Branch 0 taken 589 times.
✓ Branch 1 taken 14136 times.
14725 for(int32_t i=1; i<=24; i++)
4579 {
4580 14136 draw_fuzzy(i);
4581 14136 advanceframe(true);
4582
4583
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14136 times.
14136 if(Quit)
4584 {
4585 break;
4586 }
4587 14136 }
4588 589 }
4589
4590 587 void zapin()
4591 {
4592 587 FFCore.warpScriptCheck();
4593 587 draw_screen(tmpscr);
4594 587 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
4595 587 blit(framebuf,scrollbuf,0,0,256,0,256,224);
4596
4597 // zap out
4598 587 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4599
2/2
✓ Branch 0 taken 587 times.
✓ Branch 1 taken 14088 times.
14675 for(int32_t i=24; i>=1; i--)
4600 {
4601 14088 draw_fuzzy(i);
4602 14088 advanceframe(true);
4603
4604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14088 times.
14088 if(Quit)
4605 {
4606 break;
4607 }
4608 14088 }
4609 587 }
4610
4611
4612 235 void wavyout(bool showhero)
4613 {
4614 235 draw_screen(tmpscr, showhero);
4615
4616 235 BITMAP *wavebuf = create_bitmap_ex(8,288,224);
4617 235 clear_to_color(wavebuf,0);
4618 235 blit(framebuf,wavebuf,0,0,16,0,256,224);
4619
4620 static PALETTE wavepal;
4621
4622 int32_t ofs;
4623 235 int32_t amplitude=8;
4624
4625 235 int32_t wavelength=4;
4626 235 double palpos=0, palstep=4, palstop=126;
4627
4628 235 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4629
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 9845 times.
10079 for(int32_t i=0; i<168; i+=wavelength)
4630 {
4631
2/2
✓ Branch 0 taken 2520320 times.
✓ Branch 1 taken 9845 times.
2530165 for(int32_t l=0; l<256; l++)
4632 {
4633 2520320 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4634 2520320 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4635 2520320 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4636 2520320 }
4637
4638 9845 palpos+=palstep;
4639
4640
1/2
✓ Branch 0 taken 9845 times.
✗ Branch 1 not taken.
9845 if(palpos>=0)
4641 {
4642 9845 hw_palette = &wavepal;
4643 9845 update_hw_pal = true;
4644 9845 }
4645 else
4646 {
4647 hw_palette = &RAMpal;
4648 update_hw_pal = true;
4649 }
4650
4651
2/2
✓ Branch 0 taken 1653960 times.
✓ Branch 1 taken 9845 times.
1663805 for(int32_t j=0; j+playing_field_offset<224; j++)
4652 {
4653
2/2
✓ Branch 0 taken 423413760 times.
✓ Branch 1 taken 1653960 times.
425067720 for(int32_t k=0; k<256; k++)
4654 {
4655 423413760 ofs=0;
4656
4657
4/4
✓ Branch 0 taken 206448640 times.
✓ Branch 1 taken 216965120 times.
✓ Branch 2 taken 103224320 times.
✓ Branch 3 taken 103224320 times.
423413760 if((j<i)&&(j&1))
4658 {
4659 103224320 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/168.0))*amplitude);
4660 103224320 }
4661
4662 423413760 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4663 423413760 }
4664 1653960 }
4665
4666 9845 advanceframe(true);
4667
4668
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9844 times.
9845 if(Quit)
4669 1 break;
4670 9844 }
4671
4672 235 destroy_bitmap(wavebuf);
4673
4674 235 hw_palette = &RAMpal;
4675 235 update_hw_pal = true;
4676 235 }
4677
4678 232 void wavyin()
4679 {
4680 232 draw_screen(tmpscr);
4681
4682 232 BITMAP *wavebuf = create_bitmap_ex(8,288,224);
4683 232 clear_to_color(wavebuf,0);
4684 232 blit(framebuf,wavebuf,0,0,16,0,256,224);
4685
4686 static PALETTE wavepal;
4687
4688 232 refreshpal=false;
4689 int32_t ofs;
4690 232 int32_t amplitude=8;
4691 232 int32_t wavelength=4;
4692 232 double palpos=168, palstep=4, palstop=126;
4693
4694 232 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4695
2/2
✓ Branch 0 taken 231 times.
✓ Branch 1 taken 9703 times.
9934 for(int32_t i=0; i<168; i+=wavelength)
4696 {
4697
2/2
✓ Branch 0 taken 2483968 times.
✓ Branch 1 taken 9703 times.
2493671 for(int32_t l=0; l<256; l++)
4698 {
4699 2483968 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4700 2483968 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4701 2483968 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4702 2483968 }
4703
4704 9703 palpos-=palstep;
4705
4706
1/2
✓ Branch 0 taken 9703 times.
✗ Branch 1 not taken.
9703 if(palpos>=0)
4707 {
4708 9703 hw_palette = &wavepal;
4709 9703 update_hw_pal = true;
4710 9703 }
4711 else
4712 {
4713 hw_palette = &RAMpal;
4714 update_hw_pal = true;
4715 }
4716
4717
2/2
✓ Branch 0 taken 1630104 times.
✓ Branch 1 taken 9703 times.
1639807 for(int32_t j=0; j+playing_field_offset<224; j++)
4718 {
4719
2/2
✓ Branch 0 taken 417306624 times.
✓ Branch 1 taken 1630104 times.
418936728 for(int32_t k=0; k<256; k++)
4720 {
4721 417306624 ofs=0;
4722
4723
4/4
✓ Branch 0 taken 211158272 times.
✓ Branch 1 taken 206148352 times.
✓ Branch 2 taken 106821120 times.
✓ Branch 3 taken 104337152 times.
417306624 if((j<(167-i))&&(j&1))
4724 {
4725 104337152 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/168.0))*amplitude);
4726 104337152 }
4727
4728 417306624 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4729 417306624 }
4730 1630104 }
4731
4732 9703 advanceframe(true);
4733
4734
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9702 times.
9703 if(Quit)
4735 1 break;
4736 9702 }
4737
4738 232 destroy_bitmap(wavebuf);
4739
4740 232 hw_palette = &RAMpal;
4741 232 update_hw_pal = true;
4742 232 }
4743
4744 4335 void blackscr(int32_t fcnt,bool showsubscr)
4745 {
4746 4335 reset_pal_cycling();
4747 4335 script_drawing_commands.Clear();
4748
4749 4335 FFCore.warpScriptCheck();
4750 4335 bool showtime = game->should_show_time();
4751
2/2
✓ Branch 0 taken 4328 times.
✓ Branch 1 taken 129607 times.
133935 while(fcnt>0)
4752 {
4753 129607 clear_bitmap(framebuf);
4754
4755
2/2
✓ Branch 0 taken 59250 times.
✓ Branch 1 taken 70357 times.
129607 if(showsubscr)
4756 {
4757 70357 put_passive_subscr(framebuf,0,passive_subscreen_offset,showtime,sspUP);
4758
3/4
✓ Branch 0 taken 70357 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1230 times.
✓ Branch 3 taken 69127 times.
70357 if(get_qr(qr_SCRIPTDRAWSINWARPS) || (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN)))
4759 {
4760 1230 do_script_draws(framebuf, tmpscr, 0, playing_field_offset);
4761 1230 }
4762 70357 }
4763
4764 129607 advanceframe(true);
4765
4766
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 129600 times.
129607 if(Quit)
4767 7 break;
4768
4769 129600 --fcnt;
4770 }
4771 4335 }
4772
4773 2643 void openscreen(int32_t shape)
4774 {
4775 2643 reset_pal_cycling();
4776 2643 black_opening_count=0;
4777
4778
3/4
✓ Branch 0 taken 522 times.
✓ Branch 1 taken 2121 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 522 times.
2643 if(COOLSCROLL || shape>-1)
4779 {
4780 2121 open_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4781 2121 return;
4782 }
4783 else
4784 {
4785 522 Hero.setDontDraw(true);
4786 522 show_subscreen_dmap_dots=false;
4787 522 show_subscreen_numbers=false;
4788 522 show_subscreen_life=false;
4789 }
4790
4791 522 int32_t x=128;
4792
4793 522 FFCore.warpScriptCheck();
4794
2/2
✓ Branch 0 taken 522 times.
✓ Branch 1 taken 41760 times.
42282 for(int32_t i=0; i<80; i++)
4795 {
4796 41760 draw_screen(tmpscr);
4797 41760 x=128-(((i*128/80)/8)*8);
4798
4799
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41760 times.
41760 if(x>0)
4800 {
4801 41760 rectfill(framebuf,0,playing_field_offset,x,167+playing_field_offset,0);
4802 41760 rectfill(framebuf,256-x,playing_field_offset,255,167+playing_field_offset,0);
4803 41760 }
4804
4805 41760 advanceframe(true);
4806
4807
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41760 times.
41760 if(Quit)
4808 {
4809 break;
4810 }
4811 41760 }
4812
4813 522 Hero.setDontDraw(false);
4814 522 show_subscreen_items=true;
4815 522 show_subscreen_dmap_dots=true;
4816 522 show_subscreen_numbers=true;
4817 522 show_subscreen_life=true;
4818 2643 }
4819
4820 4 void closescreen(int32_t shape)
4821 {
4822 4 reset_pal_cycling();
4823 4 black_opening_count=0;
4824
4825
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4 if(COOLSCROLL || shape>-1)
4826 {
4827 4 close_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4828 4 return;
4829 }
4830 else
4831 {
4832 Hero.setDontDraw(true);
4833 show_subscreen_dmap_dots=false;
4834 show_subscreen_numbers=false;
4835 // show_subscreen_items=false;
4836 show_subscreen_life=false;
4837 }
4838
4839 int32_t x=128;
4840
4841 FFCore.warpScriptCheck();
4842 for(int32_t i=79; i>=0; --i)
4843 {
4844 draw_screen(tmpscr);
4845 x=128-(((i*128/80)/8)*8);
4846
4847 if(x>0)
4848 {
4849 rectfill(framebuf,0,playing_field_offset,x,167+playing_field_offset,0);
4850 rectfill(framebuf,256-x,playing_field_offset,255,167+playing_field_offset,0);
4851 }
4852
4853 advanceframe(true);
4854
4855 if(Quit)
4856 {
4857 break;
4858 }
4859 }
4860
4861 Hero.setDontDraw(false);
4862 show_subscreen_items=true;
4863 show_subscreen_dmap_dots=true;
4864 4 }
4865
4866 296 int32_t TriforceCount()
4867 {
4868 296 int32_t c=0;
4869
4870
2/2
✓ Branch 0 taken 2368 times.
✓ Branch 1 taken 296 times.
2664 for(int32_t i=1; i<=8; i++)
4871
2/2
✓ Branch 0 taken 484 times.
✓ Branch 1 taken 1884 times.
4252 if(game->lvlitems[i]&liTRIFORCE)
4872 1884 ++c;
4873
4874 296 return c;
4875 }
4876
4877 int32_t onCustomGame()
4878 {
4879 auto save = get_unset_save_slot();
4880 if (!save)
4881 return D_CLOSE;
4882
4883 if (prompt_for_quest_path(save->header->qstpath))
4884 {
4885 save->header->qstpath = qstpath;
4886 return D_O_K;
4887 }
4888
4889 return D_CLOSE;
4890 }
4891
4892 int32_t onContinue()
4893 {
4894 return D_CLOSE;
4895 }
4896
4897 int32_t onThrottleFPS()
4898 {
4899 Throttlefps = !Throttlefps;
4900 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4901 return D_O_K;
4902 }
4903
4904 int32_t onWinPosSave()
4905 {
4906 SaveWinPos = !SaveWinPos;
4907 zc_set_config(cfg_sect,"save_window_position",(int32_t)SaveWinPos);
4908 return D_O_K;
4909 }
4910 int32_t onIntegerScaling()
4911 {
4912 scaleForceInteger = !scaleForceInteger;
4913 zc_set_config("zeldadx","scaling_force_integer",(int)scaleForceInteger);
4914 return D_O_K;
4915 }
4916 int32_t onStretchGame()
4917 {
4918 stretchGame = !stretchGame;
4919 zc_set_config("zeldadx","stretch_game_area",stretchGame?1:0);
4920 return D_O_K;
4921 }
4922
4923 int32_t onClickToFreeze()
4924 {
4925 ClickToFreeze = !ClickToFreeze;
4926 zc_set_config(cfg_sect,"clicktofreeze", (int32_t)ClickToFreeze);
4927 return D_O_K;
4928 }
4929
4930 int32_t OnSaveZCConfig()
4931 {
4932 if(jwin_alert3(
4933 "Save Configuration",
4934 "Are you sure that you wish to save your present configuration settings?",
4935 "This will overwrite your prior settings!",
4936 NULL,
4937 "&Yes",
4938 "&No",
4939 NULL,
4940 'y',
4941 'n',
4942 0,
4943 get_zc_font(font_lfont)) == 1)
4944 {
4945 save_game_configs();
4946 return D_O_K;
4947 }
4948 else return D_O_K;
4949 }
4950
4951 int32_t OnnClearQuestDir()
4952 {
4953 auto current_path = fs::current_path() / "quests";
4954 if(jwin_alert3(
4955 "Clear Current Directory Cache",
4956 "Are you sure that you wish to reset where ZC Player looks for quests?",
4957 fmt::format("The new directory will be: {}", current_path.string()).c_str(),
4958 NULL,
4959 "&Yes",
4960 "&No",
4961 NULL,
4962 'y',
4963 'n',
4964 0,
4965 get_zc_font(font_lfont)) == 1)
4966 {
4967 zc_set_config("zeldadx","quest_dir","quests");
4968 flush_config_file();
4969 strcpy(qstdir,"quests");
4970 #ifdef __EMSCRIPTEN__
4971 em_sync_fs();
4972 #endif
4973 return D_O_K;
4974 }
4975 else return D_O_K;
4976 }
4977
4978 int32_t onConsole()
4979 {
4980 if ( !console_enabled )
4981 {
4982 AlertDialog("ZC Console",
4983 "Open the ZC Console?"
4984 "\nThis will display any messages logged by scripts,"
4985 " including errors.",
4986 [&](bool ret,bool)
4987 {
4988 if(ret)
4989 {
4990 FFCore.ZScriptConsole(true);
4991 }
4992 }).show();
4993 return D_O_K;
4994 }
4995 else
4996 {
4997 FFCore.ZScriptConsole(false);
4998 return D_O_K;
4999 }
5000 }
5001
5002 int32_t onClrConsoleOnReload()
5003 {
5004 clearConsoleOnReload = !clearConsoleOnReload;
5005 zc_set_config("CONSOLE","clear_console_on_reload",clearConsoleOnReload?1:0);
5006 return D_O_K;
5007 }
5008 int32_t onClrConsoleOnLoad()
5009 {
5010 clearConsoleOnLoad = !clearConsoleOnLoad;
5011 zc_set_config("CONSOLE","clear_console_on_load",clearConsoleOnLoad?1:0);
5012 return D_O_K;
5013 }
5014
5015
5016 int32_t onFrameSkip()
5017 {
5018 FrameSkip = !FrameSkip;
5019 return D_O_K;
5020 }
5021
5022 int32_t onSaveDragResize()
5023 {
5024 SaveDragResize = !SaveDragResize;
5025 zc_set_config(cfg_sect,"save_drag_resize",(int32_t)SaveDragResize);
5026 return D_O_K;
5027 }
5028
5029 int32_t onDragAspect()
5030 {
5031 DragAspect = !DragAspect;
5032 zc_set_config(cfg_sect,"drag_aspect",(int32_t)DragAspect);
5033 return D_O_K;
5034 }
5035
5036 int32_t onTransLayers()
5037 {
5038 TransLayers = !TransLayers;
5039 zc_set_config(cfg_sect,"translayers",(int32_t)TransLayers);
5040 return D_O_K;
5041 }
5042
5043 int32_t onNESquit()
5044 {
5045 NESquit = !NESquit;
5046 zc_set_config(cfg_sect,"fastquit",(int32_t)NESquit);
5047 return D_O_K;
5048 }
5049
5050 int32_t onVolKeys()
5051 {
5052 volkeys = !volkeys;
5053 zc_set_config(sfx_sect,"volkeys",(int32_t)volkeys);
5054 return D_O_K;
5055 }
5056
5057 int32_t onShowFPS()
5058 {
5059 ShowFPS = !ShowFPS;
5060 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
5061 return D_O_K;
5062 }
5063
5064 int32_t onShowTime()
5065 {
5066 ShowGameTime = !ShowGameTime;
5067 zc_set_config(cfg_sect,"showtime",ShowGameTime);
5068 return D_O_K;
5069 }
5070
5071 2161564474 bool is_Fkey(int32_t k)
5072 {
5073
2/2
✓ Branch 0 taken 219820116 times.
✓ Branch 1 taken 1941744358 times.
2161564474 switch(k)
5074 {
5075 case KEY_F1:
5076 case KEY_F2:
5077 case KEY_F3:
5078 case KEY_F4:
5079 case KEY_F5:
5080 case KEY_F6:
5081 case KEY_F7:
5082 case KEY_F8:
5083 case KEY_F9:
5084 case KEY_F10:
5085 case KEY_F11:
5086 case KEY_F12:
5087 219820116 return true;
5088 }
5089
5090 1941744358 return false;
5091 2161564474 }
5092
5093 void kb_getkey(DIALOG *d);
5094
5095 //Used by all keyboard key settings dialogues.
5096 void kb_clearjoystick(DIALOG *d)
5097 {
5098 d->flags|=D_SELECTED;
5099
5100 jwin_button_proc(MSG_DRAW,d,0);
5101 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5102 // text_mode(vc(11));
5103 textout_centre_ex(screen, font, "Press any key to clear", gui_bmp->w/2, gui_bmp->h/2 - 8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5104 textout_centre_ex(screen, font, "ESC to cancel", gui_bmp->w/2, gui_bmp->h/2, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5105
5106 update_hw_screen();
5107
5108 clear_keybuf();
5109 int32_t k = next_press_key();
5110 clear_keybuf();
5111
5112 //shnarf
5113 //47=f1
5114 //59=esc
5115 // if(k>0 && k<123 && !((k>46)&&(k<60)))
5116 // *((int32_t*)d->dp3) = k;
5117 if ( k != 59 ) *((int32_t*)d->dp3) = 0;
5118
5119
5120 d->flags&=~D_SELECTED;
5121 }
5122
5123 //Clears key to 0.
5124 //Used by all keyboard key settings dialogues.
5125 void kb_clearkey(DIALOG *d);
5126
5127 int32_t d_j_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5128 {
5129 switch(msg)
5130 {
5131 case MSG_KEY:
5132 case MSG_CLICK:
5133
5134 kb_clearjoystick(d);
5135
5136 while(gui_mouse_b())
5137 {
5138 clear_keybuf();
5139 rest(1);
5140 }
5141
5142 return D_REDRAW;
5143 }
5144
5145 return jwin_button_proc(msg,d,c);
5146 }
5147
5148 int32_t d_kbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5149 //Only used in keyboard settings dialogues to clear keys.
5150 int32_t d_k_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5151
5152 int32_t j_getbtn(DIALOG *d)
5153 {
5154 d->flags|=D_SELECTED;
5155 jwin_button_proc(MSG_DRAW,d,0);
5156 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5157 // text_mode(vc(11));
5158 int32_t y = screen->h/2 - 12;
5159 textout_centre_ex(screen, font, "Press a button", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5160 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5161 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5162
5163 update_hw_screen();
5164
5165 int32_t b = next_joy_input(true);
5166 if (b == -2)
5167 return D_CLOSE;
5168
5169 if(b>=0)
5170 *((int32_t*)d->dp3) = b;
5171
5172 d->flags&=~D_SELECTED;
5173
5174 return D_O_K;
5175 }
5176
5177 void j_getstick(DIALOG *d)
5178 {
5179 d->flags|=D_SELECTED;
5180 jwin_button_proc(MSG_DRAW,d,0);
5181 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5182 // text_mode(vc(11));
5183 int32_t y = screen->h/2 - 12;
5184 textout_centre_ex(screen, font, "Move a stick (or DPAD)", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5185 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5186 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5187
5188 update_hw_screen();
5189
5190 int32_t b = next_joy_input(false);
5191
5192 if(b>=0)
5193 *((int32_t*)d->dp3) = b;
5194
5195 d->flags&=~D_SELECTED;
5196 }
5197
5198 int32_t d_jbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5199 {
5200 switch(msg)
5201 {
5202 case MSG_KEY:
5203 case MSG_CLICK:
5204
5205 int ret = j_getbtn(d);
5206 if (ret != D_O_K)
5207 return ret;
5208
5209 while(gui_mouse_b()) {
5210 rest(1);
5211 clear_keybuf();
5212 }
5213
5214 return D_REDRAW;
5215 }
5216
5217 return jwin_button_proc(msg,d,c);
5218 }
5219
5220 int32_t d_jstick_proc(int32_t msg,DIALOG *d,int32_t c)
5221 {
5222 switch(msg)
5223 {
5224 case MSG_KEY:
5225 case MSG_CLICK:
5226
5227 j_getstick(d);
5228
5229 while(gui_mouse_b()) {
5230 rest(1);
5231 clear_keybuf();
5232 }
5233
5234 return D_REDRAW;
5235 }
5236
5237 return jwin_button_proc(msg,d,c);
5238 }
5239
5240 //shnarf
5241 extern const char *key_str[];
5242 std::string get_keystr(int key);
5243
5244 const char *pan_str[4] = { " MONO", " 1/2", " 3/4", " FULL" };
5245
5246 static char str_a[80],str_b[80],str_s[80],str_m[80],str_l[80],str_r[80],str_p[80],str_ex1[80],str_ex2[80],str_ex3[80],str_ex4[80],
5247 str_leftmod1[80],str_leftmod2[80],str_rightmod1[80],str_rightmod2[80], str_left[80], str_right[80], str_up[80], str_down[80],
5248 str_primary_stick[80], str_secondary_stick[80];
5249
5250 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c)
5251 {
5252 //these are here to bypass compiler warnings about unused arguments
5253 c=c;
5254
5255 if (d->w == 1)
5256 {
5257 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
5258 {
5259 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
5260 return D_CLOSE;
5261 }
5262 }
5263
5264 if(msg==MSG_DRAW)
5265 {
5266 switch(d->w)
5267 {
5268 case 0:
5269 sprintf(str_a,"%03d\n%s",Akey,key_str[Akey]);
5270 sprintf(str_b,"%03d\n%s",Bkey,key_str[Bkey]);
5271 sprintf(str_s,"%03d\n%s",Skey,key_str[Skey]);
5272 sprintf(str_l,"%03d\n%s",Lkey,key_str[Lkey]);
5273 sprintf(str_r,"%03d\n%s",Rkey,key_str[Rkey]);
5274 sprintf(str_p,"%03d\n%s",Pkey,key_str[Pkey]);
5275 sprintf(str_ex1,"%03d\n%s",Exkey1,key_str[Exkey1]);
5276 sprintf(str_ex2,"%03d\n%s",Exkey2,key_str[Exkey2]);
5277 sprintf(str_ex3,"%03d\n%s",Exkey3,key_str[Exkey3]);
5278 sprintf(str_ex4,"%03d\n%s",Exkey4,key_str[Exkey4]);
5279 sprintf(str_up,"%03d\n%s",DUkey,key_str[DUkey]);
5280 sprintf(str_down,"%03d\n%s",DDkey,key_str[DDkey]);
5281 sprintf(str_left,"%03d\n%s",DLkey,key_str[DLkey]);
5282 sprintf(str_right,"%03d\n%s",DRkey,key_str[DRkey]);
5283 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5284 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5285 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5286 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5287 break;
5288
5289 case 1:
5290 sprintf(str_a,"%03d\n%s",Abtn,joybtn_name(Abtn));
5291 sprintf(str_b,"%03d\n%s",Bbtn,joybtn_name(Bbtn));
5292 sprintf(str_s,"%03d\n%s",Sbtn,joybtn_name(Sbtn));
5293 sprintf(str_l,"%03d\n%s",Lbtn,joybtn_name(Lbtn));
5294 sprintf(str_r,"%03d\n%s",Rbtn,joybtn_name(Rbtn));
5295 sprintf(str_m,"%03d\n%s",Mbtn,joybtn_name(Mbtn));
5296 sprintf(str_p,"%03d\n%s",Pbtn,joybtn_name(Pbtn));
5297 sprintf(str_ex1,"%03d\n%s",Exbtn1,joybtn_name(Exbtn1));
5298 sprintf(str_ex2,"%03d\n%s",Exbtn2,joybtn_name(Exbtn2));
5299 sprintf(str_ex3,"%03d\n%s",Exbtn3,joybtn_name(Exbtn3));
5300 sprintf(str_ex4,"%03d\n%s",Exbtn4,joybtn_name(Exbtn4));
5301 sprintf(str_up,"%03d\n%s",DUbtn,joybtn_name(DUbtn));
5302 sprintf(str_down,"%03d\n%s",DDbtn,joybtn_name(DDbtn));
5303 sprintf(str_left,"%03d\n%s",DLbtn,joybtn_name(DLbtn));
5304 sprintf(str_right,"%03d\n%s",DRbtn,joybtn_name(DRbtn));
5305 sprintf(str_primary_stick,"%03d\n%s",js_stick_1_x_stick,joystick_name(js_stick_1_x_stick));
5306 sprintf(str_secondary_stick,"%03d\n%s",js_stick_2_x_stick,joystick_name(js_stick_2_x_stick));
5307 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5308 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5309 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5310 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5311 break;
5312
5313 case 2:
5314 sprintf(str_a," %3d",midi_volume);
5315 sprintf(str_l," %3d",emusic_volume);
5316 sprintf(str_r," %3d",sfx_volume);
5317 strcpy(str_s,pan_str[pan_style]);
5318 sprintf(str_leftmod1,"%3d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5319 sprintf(str_leftmod2,"%3d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5320 sprintf(str_rightmod1,"%3d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5321 sprintf(str_rightmod2,"%3d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5322 break;
5323 }
5324 }
5325
5326 return D_O_K;
5327 }
5328
5329 int32_t set_vol(void *dp3, int32_t d2)
5330 {
5331 switch(((int32_t*)dp3)[0])
5332 {
5333 case 0:
5334 midi_volume = zc_min(d2<<3,255);
5335 break;
5336
5337 case 1:
5338 digi_volume = zc_min(d2<<3,255);
5339 break;
5340
5341 case 2:
5342 emusic_volume = zc_min(d2<<3,255);
5343 break;
5344
5345 case 3:
5346 sfx_volume = zc_min(d2<<3,255);
5347 break;
5348 }
5349
5350 // text_mode(vc(11));
5351 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]," %3d",zc_min(d2<<3,255));
5352 return D_O_K;
5353 }
5354
5355 int32_t set_pan(void *dp3, int32_t d2)
5356 {
5357 pan_style = vbound(d2,0,3);
5358 // text_mode(vc(11));
5359 textout_right_ex(screen,get_zc_font(font_lfont_l), pan_str[pan_style],((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5360 return D_O_K;
5361 }
5362
5363 static int32_t gamepad_joys_list[] =
5364 {
5365 61,
5366 -1
5367 };
5368
5369 static int32_t gamepad_btn_list[] =
5370 {
5371 6,
5372 7,8,9,10,11,12,13,14,15,16,17,
5373 18,19,20,21,22,23,24,25,26,27,28,
5374 29,30,31,32,33,34,35,36,37,38,39,
5375 -1
5376 };
5377
5378 static int32_t gamepad_dirs_list[] =
5379 {
5380 40,41,42,43,
5381 44,45,46,47,
5382 48,49,50,51,
5383 52,53,54,55,
5384 56,57,58,59,
5385 60,
5386 -1
5387 };
5388
5389 static TABPANEL gamepad_tabs[] =
5390 {
5391 // (text)
5392 { (char *)"Controllers", D_SELECTED, gamepad_joys_list, 0, NULL },
5393 { (char *)"Buttons", 0, gamepad_btn_list, 0, NULL },
5394 { (char *)"Directions", 0, gamepad_dirs_list, 0, NULL },
5395 { NULL, 0, NULL, 0, NULL }
5396 };
5397
5398 const char *joy_list(int32_t index, int32_t *list_size)
5399 {
5400 if (index == -1)
5401 {
5402 *list_size = al_get_num_joysticks();
5403 return NULL;
5404 }
5405
5406 ALLEGRO_JOYSTICK* joy = al_get_joystick(index);
5407 if (!joy)
5408 {
5409 return "?";
5410 }
5411
5412 return al_get_joystick_name(joy);
5413 }
5414
5415 336 static ListData joy__list(joy_list, &font);
5416
5417 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c)
5418 {
5419 int32_t d2 = d->d2;
5420 int32_t ret = jwin_droplist_proc(msg,d,c);
5421
5422 if(d2!=d->d2)
5423 {
5424 joystick_index = d->d2;
5425 ret |= D_REDRAW_ALL;
5426 }
5427
5428 return ret;
5429 }
5430
5431 static DIALOG gamepad_dlg[] =
5432 {
5433 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5434 { jwin_win_proc, 8, 24, 304, 256, 0, 0, 0, D_EXIT, 0, 0, (void *) "Gamepad Controls", NULL, NULL },
5435 { jwin_tab_proc, 8+4, 24+23,304-8,256-52,vc(0), vc(15), 0, 0, 0, 0, (void *) gamepad_tabs, NULL, (void *)gamepad_dlg },
5436 { d_stringloader, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5437 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5438 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5439 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5440 // 6
5441 { d_dummy_proc, 14, 61, 294, 192, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5442 // 7
5443 { jwin_ctext_proc, 92, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5444 { jwin_ctext_proc, 92, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5445 { jwin_ctext_proc, 92, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5446 { jwin_ctext_proc, 92, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5447 { jwin_ctext_proc, 92, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5448 { jwin_ctext_proc, 237, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5449 { jwin_ctext_proc, 237, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5450 { jwin_ctext_proc, 237, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5451 { jwin_ctext_proc, 237, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5452 { jwin_ctext_proc, 237, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5453 { jwin_ctext_proc, 92, 244-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_m, NULL, NULL },
5454 // 18
5455 { d_jbutton_proc, 22, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Abtn},
5456 { d_jbutton_proc, 22, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bbtn},
5457 { d_jbutton_proc, 22, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Sbtn},
5458 { d_jbutton_proc, 22, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exbtn1},
5459 { d_jbutton_proc, 22, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exbtn3},
5460 { d_jbutton_proc, 167, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lbtn},
5461 { d_jbutton_proc, 167, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rbtn},
5462 { d_jbutton_proc, 167, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pbtn},
5463 { d_jbutton_proc, 167, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exbtn2},
5464 { d_jbutton_proc, 167, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exbtn4},
5465 { d_jbutton_proc, 22, 242-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Menu", NULL, &Mbtn},
5466 // 29
5467 { d_j_clearbutton_proc, 22+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Abtn},
5468 { d_j_clearbutton_proc, 22+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bbtn},
5469 { d_j_clearbutton_proc, 22+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Sbtn},
5470 { d_j_clearbutton_proc, 22+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn1},
5471 { d_j_clearbutton_proc, 22+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn3},
5472 { d_j_clearbutton_proc, 167+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lbtn},
5473 { d_j_clearbutton_proc, 167+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rbtn},
5474 { d_j_clearbutton_proc, 167+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pbtn},
5475 { d_j_clearbutton_proc, 167+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn2},
5476 { d_j_clearbutton_proc, 167+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn4},
5477 { d_j_clearbutton_proc, 22+91, 242-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Mbtn},
5478 // 40
5479 { jwin_frame_proc, 14, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5480 { jwin_frame_proc, 159, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5481 { jwin_text_proc, 30, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5482 { jwin_text_proc, 175, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5483 // 44
5484 { jwin_text_proc, 92, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5485 { jwin_text_proc, 92, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5486 { jwin_text_proc, 237, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5487 { jwin_text_proc, 237, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5488 // 48
5489 { d_jbutton_proc, 22, 82, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUbtn },
5490 { d_jbutton_proc, 22, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDbtn },
5491 { d_jbutton_proc, 167, 82, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLbtn },
5492 { d_jbutton_proc, 167, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRbtn },
5493 // 52
5494 { d_j_clearbutton_proc, 22+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUbtn},
5495 { d_j_clearbutton_proc, 22+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDbtn},
5496 { d_j_clearbutton_proc, 167+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLbtn},
5497 { d_j_clearbutton_proc, 167+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRbtn},
5498 // 56
5499 { jwin_check_proc, 22, 150, 147, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Primary: Use Analog Stick (Ignore above and use below instead)", NULL, NULL },
5500 { d_jstick_proc, 22, 165, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Primary", NULL, &js_stick_1_x_stick },
5501 { d_jstick_proc, 22, 195, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Secondary", NULL, &js_stick_2_x_stick },
5502 { jwin_text_proc, 90, 165, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_primary_stick, NULL, NULL },
5503 { jwin_text_proc, 90, 195, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_secondary_stick, NULL, NULL },
5504
5505 // 61
5506 { d_joylist_proc, 22, 62, 150, 16, 0, 0, 0, 0, 0, 0, (void *) &joy__list, NULL, NULL },
5507
5508 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5509 };
5510
5511 static int32_t keyboard_keys_list[] =
5512 {
5513 6,7,8,9,10,
5514 11,12,13,14,15,16,17,18,19,20,
5515 21,22,23,24,25,26,27,28,29,30,
5516 31,32,33,34,35,36,37,38,39,40,
5517 -1
5518 };
5519
5520 static int32_t keyboard_dirs_list[] =
5521 {
5522 41,42,43,44,
5523 45,46,47,48,
5524 49,50,51,52,
5525 53,54,55,56,
5526 -1
5527 };
5528
5529 static int32_t keyboard_mods_list[] =
5530 {
5531 57,58,59,60,
5532 61,62,63,64,
5533 65,66,67,68,
5534 69,70,71,72,
5535 -1
5536 };
5537
5538 static TABPANEL keyboard_control_tabs[] =
5539 {
5540 // (text)
5541 { (char *)"Keys", D_SELECTED, keyboard_keys_list, 0, NULL },
5542 { (char *)"Directions", 0, keyboard_dirs_list, 0, NULL },
5543 { (char *)"Cheat Mods", 0, keyboard_mods_list, 0, NULL },
5544 { NULL, 0, NULL, 0, NULL }
5545 };
5546
5547 static DIALOG keyboard_control_dlg[] =
5548 {
5549 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5550 { jwin_win_proc, 8, 39, 304, 240, 0, 0, 0, D_EXIT, 0, 0, (void *) "Keyboard Controls", NULL, NULL },
5551 { jwin_tab_proc, 8+4, 39+23,304-8,240-56,vc(0), vc(15), 0, 0, 0, 0, (void *) keyboard_control_tabs, NULL, (void *)keyboard_control_dlg },
5552 { d_stringloader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5553 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5554 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5555 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5556 // Keys
5557 // 6
5558 { jwin_frame_proc, 14, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5559 { jwin_frame_proc, 158, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5560 { jwin_frame_proc, 14, 181, 292, 67, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5561 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Standard", NULL, NULL },
5562 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Extended", NULL, NULL },
5563 // 11
5564 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5565 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5566 { jwin_text_proc, 92-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5567 { jwin_text_proc, 92-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5568 { jwin_text_proc, 92-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5569 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5570 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5571 { jwin_text_proc, 237-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5572 { jwin_text_proc, 237-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5573 { jwin_text_proc, 237-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5574 // 21
5575 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Akey},
5576 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bkey},
5577 { d_kbutton_proc, 22, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Skey},
5578 { d_kbutton_proc, 22, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exkey1},
5579 { d_kbutton_proc, 22, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exkey3},
5580 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lkey},
5581 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rkey},
5582 { d_kbutton_proc, 167, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pkey},
5583 { d_kbutton_proc, 167, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exkey2},
5584 { d_kbutton_proc, 167, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exkey4},
5585 // 31
5586 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Akey},
5587 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bkey},
5588 { d_k_clearbutton_proc, 22+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Skey},
5589 { d_k_clearbutton_proc, 22+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey1},
5590 { d_k_clearbutton_proc, 22+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey3},
5591 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lkey},
5592 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rkey},
5593 { d_k_clearbutton_proc, 167+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pkey},
5594 { d_k_clearbutton_proc, 167+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey2},
5595 { d_k_clearbutton_proc, 167+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey4},
5596 // Dirs
5597 // 41
5598 { jwin_frame_proc, 14, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5599 { jwin_frame_proc, 159, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5600 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5601 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5602 // 45
5603 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5604 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5605 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5606 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5607 // 49
5608 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUkey},
5609 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDkey},
5610 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLkey},
5611 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRkey},
5612 // 53
5613 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUkey},
5614 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDkey},
5615 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLkey},
5616 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRkey},
5617 // Mods
5618 // 57
5619 { jwin_frame_proc, 14, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5620 { jwin_frame_proc, 158, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5621 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Left", NULL, NULL },
5622 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Right", NULL, NULL },
5623 // 61
5624 { jwin_text_proc, 92-26, 101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod1, NULL, NULL },
5625 { jwin_text_proc, 92-26, 129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod1, NULL, NULL },
5626 { jwin_text_proc, 237-4-22,101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod2, NULL, NULL },
5627 { jwin_text_proc, 237-4-22,129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod2, NULL, NULL },
5628 // 65
5629 { d_kbutton_proc, 22, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[0]},
5630 { d_kbutton_proc, 22, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[2]},
5631 { d_kbutton_proc, 167, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[1]},
5632 { d_kbutton_proc, 167, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[3]},
5633 // 69
5634 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[0]},
5635 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[2]},
5636 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[1]},
5637 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[3]},
5638 // 73
5639 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5640 };
5641
5642 int32_t midi_dp[3] = {0,0,0};
5643 int32_t emus_dp[3] = {2,0,0};
5644 int32_t sfx_dp[3] = {3,0,0};
5645 int32_t pan_dp[3] = {0,0,0};
5646
5647 static DIALOG sound_dlg[] =
5648 {
5649 //(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5650 336 { jwin_win_proc, 0, 0, 320, 178, 0, 0, 0, D_EXIT, 0, 0, (void *) "Sound Settings", NULL, NULL },
5651 336 { d_stringloader, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5652 336 { jwin_button_proc, 58, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5653 336 { jwin_button_proc, 138, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5654 336 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5655 336 { jwin_frame_proc, 10, 28, 300, 112, 0, 0, 0, 0, FR_ETCHED, 0, NULL, NULL, NULL },
5656 336 { jwin_rtext_proc, 190, 40, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_a, NULL, NULL },
5657 336 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5658 336 { jwin_rtext_proc, 190, 56, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_l, NULL, NULL },
5659 336 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5660 // 10
5661 336 { jwin_rtext_proc, 190, 72, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_r, NULL, NULL },
5662 336 { jwin_rtext_proc, 190, 88, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_s, NULL, NULL },
5663 336 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5664 336 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5665 336 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5666 336 { jwin_slider_proc, 196, 40, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, midi_dp },
5667 336 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5668 336 { jwin_slider_proc, 196, 56, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, emus_dp },
5669 336 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5670 336 { jwin_slider_proc, 196, 72, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, sfx_dp },
5671 //20
5672 336 { jwin_slider_proc, 196, 88, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 3, 0, NULL, (void *) set_pan, pan_dp },
5673 336 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5674 336 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5675 336 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5676 336 { jwin_text_proc, 17, 40, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "MIDI Volume", NULL, NULL },
5677 336 { jwin_text_proc, 17, 56, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Music Volume (Enhanced Music)", NULL, NULL },
5678 336 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5679 336 { jwin_text_proc, 17, 72, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Volume", NULL, NULL },
5680 336 { jwin_text_proc, 17, 88, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Pan", NULL, NULL },
5681 336 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5682 //30
5683 336 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5684 336 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5685 336 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5686 };
5687
5688 char zc_builddate[80];
5689 char zc_aboutstr[80];
5690
5691 static DIALOG about_dlg[] =
5692 {
5693 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5694 { jwin_win_proc, 68, 52, 184, 154, 0, 0, 0, D_EXIT, 0, 0, (void *) "About", NULL, NULL },
5695 { jwin_button_proc, 140, 176, 41, 21, vc(14), 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5696 { jwin_ctext_proc, 160, 84, 0, 8, vc(0), vc(11), 0, 0, 0, 0, zc_aboutstr, NULL, NULL },
5697 { jwin_ctext_proc, 160, 92, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5698 { jwin_ctext_proc, 160, 100, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, zc_builddate, NULL, NULL },
5699 { jwin_text_proc, 88, 124, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Coded by:", NULL, NULL },
5700 { jwin_text_proc, 88, 132, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Phantom Menace", NULL, NULL },
5701 { jwin_text_proc, 88, 144, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Produced by:", NULL, NULL },
5702 { jwin_text_proc, 88, 152, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Armageddon Games", NULL, NULL },
5703 { jwin_frame_proc, 80, 117, 160, 50, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5704 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5705 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5706 };
5707
5708
5709 static DIALOG quest_dlg[] =
5710 {
5711 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5712 { jwin_win_proc, 68, 25, 184, 190, 0, 0, 0, D_EXIT, 0, 0, (void *) "Quest Info", NULL, NULL },
5713 { jwin_edit_proc, 84, 54, 152, 16, 0, 0, 0, D_READONLY, 100, 0, NULL, NULL, NULL },
5714 { jwin_text_proc, 89, 84, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
5715 { jwin_text_proc, 152, 84, 24, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5716 { jwin_text_proc, 89, 94, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Version:", NULL, NULL },
5717 { jwin_text_proc, 160, 94, 64, 8, vc(7), vc(11), 0, 0, 0, 0, header_version_nul_term, NULL, NULL },
5718 { jwin_text_proc, 89, 104, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "ZQ Version:", NULL, NULL },
5719 { jwin_text_proc, 130, 104, 64, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5720 { jwin_text_proc, 84, 126, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Title:", NULL, NULL },
5721 { jwin_textbox_proc, 84, 136, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.title, NULL, NULL },
5722 { jwin_text_proc, 84, 168, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Author:", NULL, NULL },
5723 { jwin_textbox_proc, 84, 178, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.author, NULL, NULL },
5724 { jwin_frame_proc, 84, 79, 152, 38, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5725 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5726 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5727 };
5728
5729 static DIALOG triforce_dlg[] =
5730 {
5731 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
5732 { jwin_win_proc, 72, 64, 177, 105, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
5733 // 1
5734 { jwin_check_proc, 129, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "1", NULL, NULL },
5735 { jwin_check_proc, 129, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "2", NULL, NULL },
5736 { jwin_check_proc, 129, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "3", NULL, NULL },
5737 { jwin_check_proc, 129, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "4", NULL, NULL },
5738 { jwin_check_proc, 172, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "5", NULL, NULL },
5739 { jwin_check_proc, 172, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "6", NULL, NULL },
5740 { jwin_check_proc, 172, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "7", NULL, NULL },
5741 { jwin_check_proc, 172, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "8", NULL, NULL },
5742 // 9
5743 { jwin_button_proc, 90, 144, 61, 21, vc(0), vc(11), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
5744 { jwin_button_proc, 170, 144, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5745 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5746 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5747 };
5748
5749 int32_t onToggleRecordingNewSaves()
5750 {
5751 if (zc_get_config("zeldadx", "replay_new_saves", false))
5752 {
5753 zc_set_config("zeldadx", "replay_new_saves", false);
5754 }
5755 else
5756 {
5757 zc_set_config("zeldadx", "replay_new_saves", true);
5758 jwin_alert("Recording", "Newly created saves will be recorded and written to a replay file.",
5759 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5760 }
5761 return D_O_K;
5762 }
5763
5764 #ifdef HAS_CURL
5765 int32_t onToggleAutoUploadReplays()
5766 {
5767 if (zc_get_config("zeldadx", "replay_upload", false))
5768 {
5769 zc_set_config("zeldadx", "replay_upload", false);
5770 }
5771 else
5772 {
5773 zc_set_config("zeldadx", "replay_upload", true);
5774 jwin_alert("Replays", "Replays will be automatically uploaded. This helps development by",
5775 " preventing bugs and simplifying bug reports.",
5776 "Upload will happen no more than once a week when closing ZC",
5777 "OK",NULL,13,27,get_zc_font(font_lfont));
5778
5779 if (!zc_get_config("zeldadx", "replay_new_saves", false))
5780 onToggleRecordingNewSaves();
5781 }
5782 return D_O_K;
5783 }
5784
5785 int32_t onUploadReplays()
5786 {
5787 if(jwin_alert3(
5788 "Upload replays",
5789 "Upload your replays now to assist in development?",
5790 NULL,
5791 NULL,
5792 "&Yes",
5793 "&No",
5794 NULL,
5795 'y',
5796 'n',
5797 0,
5798 get_zc_font(font_lfont)) == 1)
5799 {
5800 int num_uploaded = replay_upload();
5801 jwin_alert("Upload replays", fmt::format("Uploaded {} replays", num_uploaded).c_str(),
5802 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5803 }
5804 return D_O_K;
5805 }
5806
5807 int32_t onClearUploadCache()
5808 {
5809 if(jwin_alert3(
5810 "Upload replays",
5811 "Clear the upload cache?",
5812 "This simply deletes replays/state.json. There's no harm in doing this, but",
5813 "likely is not necessary.",
5814 "&Yes",
5815 "&No",
5816 NULL,
5817 'y',
5818 'n',
5819 0,
5820 get_zc_font(font_lfont)) == 1)
5821 {
5822 replay_upload_clear_cache();
5823 }
5824 return D_O_K;
5825 }
5826 #endif
5827
5828 int32_t onToggleSnapshotAllFrames()
5829 {
5830 replay_set_snapshot_all_frames(!replay_is_snapshot_all_frames());
5831 return D_O_K;
5832 }
5833
5834 int32_t onStopReplayOrRecord()
5835 {
5836 if (replay_is_replaying())
5837 {
5838 replay_quit();
5839 }
5840 else if (replay_get_mode() == ReplayMode::Record)
5841 {
5842 if (!replay_get_meta_bool("test_mode"))
5843 {
5844 jwin_alert("Recording", "You cannot stop recording a save file.",
5845 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5846 return D_CLOSE;
5847 }
5848
5849 if (jwin_alert("Stop Recording",
5850 "Save replay to disk and stop recording?",
5851 "This will stop the recording.",
5852 NULL,
5853 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5854 return D_CLOSE;
5855
5856 replay_save();
5857 replay_stop();
5858 }
5859 return D_O_K;
5860 }
5861
5862 static int32_t handle_on_load_replay(ReplayMode mode)
5863 {
5864 bool ctrl = CHECK_CTRL_CMD;
5865 if (Playing)
5866 {
5867 if (jwin_alert("Replay - Warning!",
5868 "Loading a replay will exit the current game.",
5869 "All unsaved progress will be lost.",
5870 "Do you wish to continue?",
5871 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5872 return D_CLOSE;
5873 }
5874
5875 std::string mode_string = replay_mode_to_string(mode);
5876 mode_string[0] = std::toupper(mode_string[0]);
5877
5878 std::string line_1 = "Select a replay file to play back.";
5879 std::string line_2 = "You won't be able to save, and it won't effect existing saves.";
5880 std::string line_3 = "You can stop the replay and take over manually any time.";
5881 if (mode == ReplayMode::Update)
5882 {
5883 line_1 = "Select a replay file to update.";
5884 line_2 = "WARNING: be sure to back up the zplay file";
5885 line_3 = "and verify that the updated replay works as expected!";
5886 }
5887
5888 if (jwin_alert(mode_string.c_str(),
5889 line_1.c_str(),
5890 line_2.c_str(),
5891 line_3.c_str(),
5892 "OK","Nevermind",13,27,get_zc_font(font_lfont)) == 1)
5893 {
5894 std::string replay_path = "replays/";
5895 if(ctrl && devpwd())
5896 replay_path = "../../tests/replays/";
5897 std::string prompt = fmt::format("Load Replay ({})", REPLAY_EXTENSION);
5898 if (auto result = prompt_for_existing_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5899 replay_path = *result;
5900 else
5901 return D_CLOSE;
5902
5903 replay_quit();
5904 load_replay_file_deferred(mode, replay_path);
5905 Quit = qRESET;
5906 return D_CLOSE;
5907 }
5908 return D_O_K;
5909 }
5910
5911 int32_t onLoadReplay()
5912 {
5913 return handle_on_load_replay(ReplayMode::Replay);
5914 }
5915
5916 int32_t onLoadReplayAssert()
5917 {
5918 return handle_on_load_replay(ReplayMode::Assert);
5919 }
5920
5921 int32_t onLoadReplayUpdate()
5922 {
5923 return handle_on_load_replay(ReplayMode::Update);
5924 }
5925
5926 int32_t onSaveReplay()
5927 {
5928 if (replay_get_mode() == ReplayMode::Record)
5929 {
5930 if (!replay_get_meta_bool("test_mode"))
5931 {
5932 if (jwin_alert("Save Replay",
5933 "This will save a copy of the replay up to this point.",
5934 "The official replay file will be untouched.",
5935 "Do you wish to continue?",
5936 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5937 {
5938 return D_CLOSE;
5939 }
5940
5941 std::string replay_path = replay_get_replay_path().string();
5942 std::string prompt = fmt::format("Save Replay ({})", REPLAY_EXTENSION);
5943 if (auto result = prompt_for_new_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5944 replay_path = *result;
5945 else
5946 return D_CLOSE;
5947
5948 if (fileexists(replay_path.c_str()))
5949 {
5950 jwin_alert("Save Replay", "You cannot overwrite an existing file.",
5951 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5952 return D_CLOSE;
5953 }
5954
5955 replay_save(replay_path);
5956 }
5957 else
5958 {
5959 replay_save();
5960 }
5961 }
5962 return D_O_K;
5963 }
5964
5965 enum
5966 {
5967 MENUID_REPLAY_RECORDNEW,
5968 MENUID_REPLAY_STOP,
5969 MENUID_REPLAY_SAVE,
5970 MENUID_REPLAY_SNAP_ALL,
5971 MENUID_REPLAY_AUTOUPLOAD,
5972 MENUID_REPLAY_UPLOAD,
5973 MENUID_REPLAY_CLEARUPLOADCACHE,
5974 };
5975
1/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
336 static NewMenu replay_menu
5976 4368 {
5977
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Record new saves", onToggleRecordingNewSaves, MENUID_REPLAY_RECORDNEW },
5978
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 {},
5979
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Stop replay", onStopReplayOrRecord, MENUID_REPLAY_STOP },
5980
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Load replay", onLoadReplay },
5981
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Load replay (assert)", onLoadReplayAssert },
5982
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Load replay (update)", onLoadReplayUpdate },
5983
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Save replay", onSaveReplay, MENUID_REPLAY_SAVE },
5984
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Snapshot all frames", onToggleSnapshotAllFrames, MENUID_REPLAY_SNAP_ALL },
5985 #ifdef HAS_CURL
5986
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 {},
5987
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Auto upload replays", onToggleAutoUploadReplays, MENUID_REPLAY_AUTOUPLOAD },
5988
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Upload replays", onUploadReplays, MENUID_REPLAY_UPLOAD },
5989
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Clear upload cache", onClearUploadCache, MENUID_REPLAY_CLEARUPLOADCACHE },
5990 #endif
5991 };
5992
5993 static DIALOG credits_dlg[] =
5994 {
5995 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5996 { jwin_win_proc, 40, 38, 241, 173, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "ZQuest Classic Credits", NULL, NULL },
5997 { jwin_frame_proc, 47, 65, 227, 115, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
5998 { d_bitmap_proc, 49, 67, 222, 110, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
5999 { jwin_button_proc, 140, 184, 41, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6000 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6001 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6002 };
6003
6004 336 static ListData dmap_list(dmaplist, &font);
6005
6006 static DIALOG goto_dlg[] =
6007 {
6008 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6009 { jwin_win_proc, 48, 25, 205, 100, 0, 0, 0, D_EXIT, 0, 0, (void *) "Goto Location", NULL, NULL },
6010 { jwin_button_proc, 90, 176-78, 61, 21, vc(14), 0, 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6011 { jwin_button_proc, 170, 176-78, 61, 21, vc(14), 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6012 { jwin_text_proc, 55, 129-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
6013 { jwin_droplist_proc, 88, 126-75, 160, 16, 0, 0, 0, 0, 0, 0, (void *) &dmap_list, NULL, NULL },
6014 { jwin_text_proc, 55, 149-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
6015 { jwin_edit_proc, 132, 146-75, 91, 16, 0, 0, 0, 0, 2, 0, NULL, NULL, NULL },
6016 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6017 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6018 };
6019
6020 int32_t onGoTo()
6021 {
6022 bool music = false;
6023 music = music;
6024 sprintf(cheat_goto_screen_str,"%X",cheat_goto_screen);
6025
6026 goto_dlg[0].dp2=get_zc_font(font_lfont);
6027 goto_dlg[4].d2=cheat_goto_dmap;
6028 goto_dlg[6].dp=cheat_goto_screen_str;
6029
6030 clear_keybuf();
6031
6032 large_dialog(goto_dlg);
6033
6034 if(do_zqdialog(goto_dlg,4)==1)
6035 {
6036 int dmap = goto_dlg[4].d2;
6037 int screen = zc_xtoi(cheat_goto_screen_str);
6038 int adjusted_screen = screen + DMaps[dmap].xoff;
6039 if (adjusted_screen < 0 || adjusted_screen >= 128)
6040 {
6041 InfoDialog("Invalid screen", fmt::format("The screen {:02X} is out of bounds.", adjusted_screen)).show();
6042 }
6043 else
6044 {
6045 cheats_enqueue(Cheat::GoTo, dmap, screen);
6046 }
6047 };
6048
6049 return D_O_K;
6050 }
6051
6052 int32_t onGoToComplete()
6053 {
6054 if(!Playing)
6055 {
6056 return D_O_K;
6057 }
6058
6059 enter_sys_pal();
6060 music_pause();
6061 pause_all_sfx();
6062 onGoTo();
6063 eat_buttons();
6064
6065 zc_readrawkey(KEY_ESC);
6066
6067 exit_sys_pal();
6068 music_resume();
6069 resume_all_sfx();
6070 return D_O_K;
6071 }
6072
6073 int32_t onCredits()
6074 {
6075 return D_O_K;
6076 }
6077
6078 const char *midilist(int32_t index, int32_t *list_size)
6079 {
6080 if(index<0)
6081 {
6082 *list_size=0;
6083
6084 for(int32_t i=0; i<MAXMIDIS; i++)
6085 if(tunes[i].data)
6086 ++(*list_size);
6087
6088 return NULL;
6089 }
6090
6091 int32_t i=0,m=0;
6092
6093 while(m<=index && i<=MAXMIDIS)
6094 {
6095 if(tunes[i].data)
6096 ++m;
6097
6098 ++i;
6099 }
6100
6101 --i;
6102
6103 if(i==MAXMIDIS && m<index)
6104 return "(null)";
6105
6106 return tunes[i].title;
6107 }
6108
6109 /* ------- MIDI info stuff -------- */
6110
6111 char *text;
6112 midi_info *zmi;
6113 bool dialog_running;
6114 bool listening;
6115
6116 void get_info(int32_t index);
6117
6118 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c)
6119 {
6120 int32_t d2 = d->d2;
6121 int32_t ret = jwin_droplist_proc(msg,d,c);
6122
6123 if(d2!=d->d2)
6124 {
6125 get_info(d->d2);
6126 }
6127
6128 return ret;
6129 }
6130
6131 int32_t d_listen_proc(int32_t msg,DIALOG *d,int32_t c)
6132 {
6133 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6134
6135 int32_t ret = jwin_button_proc(msg,d,c);
6136
6137 if(ret == D_CLOSE)
6138 {
6139 // get current midi index
6140 int32_t index = (d+(d->d1))->d2;
6141 int32_t i=0, m=0;
6142
6143 while(m<=index && i<=MAXMIDIS)
6144 {
6145 if(tunes[i].data)
6146 ++m;
6147
6148 ++i;
6149 }
6150
6151 --i;
6152 jukebox(i);
6153 listening = true;
6154 ret = D_O_K;
6155 }
6156
6157 return ret;
6158 }
6159
6160 int32_t d_savemidi_proc(int32_t msg,DIALOG *d,int32_t c)
6161 {
6162 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6163
6164 int32_t ret = jwin_button_proc(msg,d,c);
6165
6166 if(ret == D_CLOSE)
6167 {
6168 // get current midi index
6169 int32_t index = (d+(d->d1))->d2;
6170 int32_t i=0, m=0;
6171
6172 while(m<=index && i<=MAXMIDIS)
6173 {
6174 if(tunes[i].data)
6175 ++m;
6176
6177 ++i;
6178 }
6179
6180 --i;
6181
6182 char title[40] = "Save MIDI: ";
6183 static EXT_LIST list[] =
6184 {
6185 { (char *)"MIDI files (*.mid)", (char *)"mid" },
6186 { NULL, NULL }
6187 };
6188
6189 strcpy(title+11, tunes[i].title);
6190 title[39] = '\0';
6191
6192 std::string fname;
6193 if (auto result = prompt_for_new_file(title, "", list, "tune.mid"))
6194 fname = *result;
6195 else
6196 goto done;
6197
6198 if(exists(fname.c_str()))
6199 {
6200 if(jwin_alert(title, fname.c_str(), "already exists.", "Overwrite it?", "&Yes","&No",'y','n',get_zc_font(font_lfont))==2)
6201 goto done;
6202 }
6203
6204 // save midi i
6205
6206 if (save_midi(fname.c_str(), tunes[i].data) != 0)
6207 jwin_alert(title, "Error saving MIDI to", fname.c_str(), NULL, "Darn", NULL,13,27,get_zc_font(font_lfont));
6208
6209 done:
6210 chop_path(fname.data());
6211 ret = D_REDRAW;
6212 }
6213
6214 return ret;
6215 }
6216
6217 336 static ListData midi_list(midilist, &font);
6218
6219 static DIALOG midi_dlg[] =
6220 {
6221 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6222 { jwin_win_proc, 8, 28, 304, 184, 0, 0, 0, D_EXIT, 0, 0, (void *) "MIDI Info", NULL, NULL },
6223 { jwin_text_proc, 32, 60, 40, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Tune:", NULL, NULL },
6224 { d_midilist_proc, 80, 56, 192, 16, 0, 0, 0, 0, 0, 0, (void *) &midi_list, NULL, NULL },
6225 { jwin_textbox_proc, 15, 80, 290, 96, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6226 { d_listen_proc, 24, 183, 72, 21, 0, 0, 'l', D_EXIT, -2, 0, (void *) "&Listen", NULL, NULL },
6227 { d_savemidi_proc, 108, 183, 72, 21, 0, 0, 's', D_EXIT, -3, 0, (void *) "&Save", NULL, NULL },
6228 { jwin_button_proc, 236, 183, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6229 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6230 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6231 };
6232
6233 void get_info(int32_t index)
6234 {
6235 int32_t i=0, m=0;
6236
6237 while(m<=index && i<=MAXMIDIS)
6238 {
6239 if(tunes[i].data)
6240 ++m;
6241
6242 ++i;
6243 }
6244
6245 --i;
6246
6247 if(i==MAXMIDIS && m<index)
6248 strcpy(text,"(null)");
6249 else
6250 {
6251 get_midi_info(tunes[i].data,zmi);
6252 get_midi_text(tunes[i].data,zmi,text);
6253 }
6254
6255 midi_dlg[0].dp2=get_zc_font(font_lfont);
6256 midi_dlg[3].dp = text;
6257 midi_dlg[3].d1 = midi_dlg[3].d2 = 0;
6258 midi_dlg[5].flags = (tunes[i].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6259
6260 if(dialog_running)
6261 {
6262 jwin_textbox_proc(MSG_DRAW,midi_dlg+3,0);
6263 d_savemidi_proc(MSG_DRAW,midi_dlg+5,0);
6264 }
6265 }
6266
6267 int32_t onMIDICredits()
6268 {
6269 text = (char*)malloc(4096);
6270 zmi = (midi_info*)malloc(sizeof(midi_info));
6271
6272 if(!text || !zmi)
6273 {
6274 jwin_alert(NULL,"Not enough memory",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6275 return D_O_K;
6276 }
6277
6278 bool do_pause_midi = midi_pos >= 0 && currmidi;
6279 auto restore_midi = currmidi;
6280 if(do_pause_midi)
6281 {
6282 paused_midi_pos = midi_pos;
6283 stop_midi();
6284 midi_suspended = midissuspHALTED;
6285 }
6286
6287 midi_dlg[0].dp2=get_zc_font(font_lfont);
6288 midi_dlg[2].d1 = 0;
6289 midi_dlg[2].d2 = 0;
6290 midi_dlg[4].flags = D_EXIT;
6291 midi_dlg[5].flags = (tunes[midi_dlg[2].d1].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6292
6293 listening = false;
6294 dialog_running=false;
6295 get_info(0);
6296
6297 dialog_running=true;
6298
6299 large_dialog(midi_dlg);
6300
6301 do_zqdialog(midi_dlg,0);
6302 dialog_running=false;
6303
6304 if(listening)
6305 music_stop();
6306
6307 if(do_pause_midi)
6308 {
6309 // TODO: this probably doesn't resume midis nicely when scrolling (or in some other inner-gameloop).
6310 midi_suspended = midissuspRESUME;
6311 currmidi = restore_midi;
6312 midi_pos = paused_midi_pos;
6313 }
6314
6315 if(text) free(text);
6316 if(zmi) free(zmi);
6317 return D_O_K;
6318 }
6319
6320 int32_t onAbout()
6321 {
6322 char buf1[80]={0};
6323 std::ostringstream oss;
6324 sprintf(buf1,ZC_PLAYER_NAME);
6325 oss << buf1 << '\n';
6326 sprintf(buf1,"Version: %s", getVersionString());
6327 oss << buf1 << '\n';
6328 sprintf(buf1,"Build Date: %s %s, %d at @ %s %s", dayextension(BUILDTM_DAY).c_str(), (char*)months[BUILDTM_MONTH], BUILDTM_YEAR, __TIME__, __TIMEZONE__);
6329 oss << buf1 << '\n';
6330 sprintf(buf1, "Built By: %s", DEV_SIGNOFF);
6331 oss << buf1 << '\n';
6332
6333 InfoDialog("About ZC", oss.str()).show();
6334 return D_O_K;
6335 }
6336
6337 int32_t onQuest()
6338 {
6339 char fname[100];
6340 strcpy(fname, get_filename(qstpath));
6341 quest_dlg[0].dp2=get_zc_font(font_lfont);
6342 quest_dlg[1].dp = fname;
6343
6344 if(QHeader.quest_number==0)
6345 sprintf(str_a,"Custom");
6346 else
6347 sprintf(str_a,"%d",QHeader.quest_number);
6348
6349 sprintf(str_s,"%s",QHeader.getVerStr());
6350
6351 quest_dlg[11].d1 = quest_dlg[9].d1 = 0;
6352 quest_dlg[11].d2 = quest_dlg[9].d2 = 0;
6353
6354 large_dialog(quest_dlg);
6355
6356 do_zqdialog(quest_dlg, 0);
6357 return D_O_K;
6358 }
6359
6360 void call_vidmode_dlg();
6361 int32_t onVidMode()
6362 {
6363 call_vidmode_dlg();
6364 return D_O_K;
6365 }
6366
6367 #define addToHash(c,b,h) if(h->find(c ## key) == h->end()) \
6368 {(*h)[c ## key]=true;} else { if ( c ## key != 0 ) b = false;}
6369 //Added an extra statement, so that if the key is cleared to 0, the cleared
6370 //keybinding status need not be unique. -Z ( 1st April, 2019 )
6371
6372 void load_ukeys(int32_t* arr)
6373 {
6374 arr[ukey_a] = Akey;
6375 arr[ukey_b] = Bkey;
6376 arr[ukey_s] = Skey;
6377 arr[ukey_l] = Lkey;
6378 arr[ukey_r] = Rkey;
6379 arr[ukey_p] = Pkey;
6380 arr[ukey_ex1] = Exkey1;
6381 arr[ukey_ex2] = Exkey2;
6382 arr[ukey_ex3] = Exkey3;
6383 arr[ukey_ex4] = Exkey4;
6384 arr[ukey_du] = DUkey;
6385 arr[ukey_dd] = DDkey;
6386 arr[ukey_dl] = DLkey;
6387 arr[ukey_dr] = DRkey;
6388 arr[ukey_mod1a] = cheat_modifier_keys[0];
6389 arr[ukey_mod1b] = cheat_modifier_keys[1];
6390 arr[ukey_mod2a] = cheat_modifier_keys[2];
6391 arr[ukey_mod2b] = cheat_modifier_keys[3];
6392 };
6393
6394 static const char* ukey_names[] = {
6395 "A", "B", "Start", "L", "R", "Map",
6396 "Ex1", "Ex2", "Ex3", "Ex4", "Up", "Down",
6397 "Left", "Right", "Cheat Mod L1", "Cheat Mod L2",
6398 "Cheat Mod R1", "Cheat Mod R2",
6399 };
6400 std::string get_ukey_name(int32_t k)
6401 {
6402 if (k < num_ukey) return ukey_names[k];
6403 return "";
6404 }
6405
6406 int32_t onKeyboard()
6407 {
6408 int32_t a = Akey;
6409 int32_t b = Bkey;
6410 int32_t s = Skey;
6411 int32_t l = Lkey;
6412 int32_t r = Rkey;
6413 int32_t p = Pkey;
6414 int32_t ex1 = Exkey1;
6415 int32_t ex2 = Exkey2;
6416 int32_t ex3 = Exkey3;
6417 int32_t ex4 = Exkey4;
6418 int32_t du = DUkey;
6419 int32_t dd = DDkey;
6420 int32_t dl = DLkey;
6421 int32_t dr = DRkey;
6422 int32_t mod1a = cheat_modifier_keys[0];
6423 int32_t mod1b = cheat_modifier_keys[1];
6424 int32_t mod2a = cheat_modifier_keys[2];
6425 int32_t mod2b = cheat_modifier_keys[3];
6426 bool done=false;
6427 int32_t ret;
6428
6429 keyboard_control_dlg[0].dp2=get_zc_font(font_lfont);
6430
6431 large_dialog(keyboard_control_dlg);
6432
6433 while(!done)
6434 {
6435 ret = do_zqdialog(keyboard_control_dlg,3);
6436
6437 if(ret==3) // OK
6438 {
6439 int32_t ukeys[num_ukey];
6440 load_ukeys(ukeys);
6441 std::vector<std::string> uniqueError;
6442 for(int32_t q = 0; q < num_ukey; ++q)
6443 {
6444 for(int32_t p = q+1; p < num_ukey; ++p)
6445 {
6446 if(ukeys[q] == ukeys[p] && ukeys[q] != 0)
6447 {
6448 char buf[64];
6449 sprintf(buf, "'%s' conflicts with '%s'", get_ukey_name(q).c_str(), get_ukey_name(p).c_str());
6450 std::string str(buf);
6451 uniqueError.push_back(str);
6452 }
6453 }
6454 }
6455 if(uniqueError.size() == 0)
6456 {
6457 done = true;
6458 save_control_configs(true);
6459 }
6460 else
6461 {
6462 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, keyboard_control_dlg[0].w,keyboard_control_dlg[0].h, 2);
6463 box_out("Cannot have duplicate keybinds!"); box_eol();
6464 for(std::vector<std::string>::iterator it = uniqueError.begin();
6465 it != uniqueError.end(); ++it)
6466 {
6467 box_out((*it).c_str()); box_eol();
6468 }
6469 box_end(true);
6470 }
6471 }
6472 else // Cancel
6473 {
6474 Akey = a;
6475 Bkey = b;
6476 Skey = s;
6477 Lkey = l;
6478 Rkey = r;
6479 Pkey = p;
6480 Exkey1 = ex1;
6481 Exkey2 = ex2;
6482 Exkey3 = ex3;
6483 Exkey4 = ex4;
6484 DUkey = du;
6485 DDkey = dd;
6486 DLkey = dl;
6487 DRkey = dr;
6488 cheat_modifier_keys[0] = mod1a;
6489 cheat_modifier_keys[1] = mod1b;
6490 cheat_modifier_keys[2] = mod2a;
6491 cheat_modifier_keys[3] = mod2b;
6492
6493 done=true;
6494 }
6495
6496 rest(1);
6497 }
6498
6499 return D_O_K;
6500 }
6501
6502 int32_t onGamepad()
6503 {
6504 if (al_get_num_joysticks() == 0)
6505 {
6506 InfoDialog("ZC", "No gamepads detected.").show();
6507 return D_O_K;
6508 }
6509
6510 int32_t a = Abtn;
6511 int32_t b = Bbtn;
6512 int32_t s = Sbtn;
6513 int32_t l = Lbtn;
6514 int32_t r = Rbtn;
6515 int32_t m = Mbtn;
6516 int32_t p = Pbtn;
6517 int32_t ex1 = Exbtn1;
6518 int32_t ex2 = Exbtn2;
6519 int32_t ex3 = Exbtn3;
6520 int32_t ex4 = Exbtn4;
6521 int32_t up = DUbtn;
6522 int32_t down = DDbtn;
6523 int32_t left = DLbtn;
6524 int32_t right = DRbtn;
6525 int32_t joy = joystick_index;
6526 int32_t stick_1 = js_stick_1_x_stick;
6527 int32_t stick_2 = js_stick_2_x_stick;
6528
6529 gamepad_dlg[0].dp2=get_zc_font(font_lfont);
6530 if(analog_movement)
6531 gamepad_dlg[56].flags|=D_SELECTED;
6532 else
6533 gamepad_dlg[56].flags&=~D_SELECTED;
6534
6535 // TODO: should use controller device GUID or name instead of index, otherwise this value is not
6536 // consistent unless exact same number of joysticks is always connected. Name is problematic b/c
6537 // xinput driver doesn't actually get a name (at least, doesn't for my Xbox controller).
6538 // TODO: should store gamepad control mappings per-controller, otherwise switching joystick
6539 // requires remapping every time.
6540 if (joystick_index >= al_get_num_joysticks())
6541 joystick_index = 0;
6542 gamepad_dlg[61].d2 = joystick_index;
6543
6544 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6545 if (!gamepad_dlg_cur_joystick)
6546 {
6547 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6548 return D_CLOSE;
6549 }
6550
6551 large_dialog(gamepad_dlg);
6552
6553 int32_t ret = do_zqdialog(gamepad_dlg,4);
6554
6555 if(ret == 4) //OK
6556 {
6557 analog_movement = gamepad_dlg[56].flags&D_SELECTED;
6558 joystick_index = gamepad_dlg[61].d2;
6559 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6560 if (!gamepad_dlg_cur_joystick)
6561 {
6562 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6563 return D_CLOSE;
6564 }
6565 js_stick_1_y_stick = js_stick_1_x_stick;
6566 js_stick_2_y_stick = js_stick_2_x_stick;
6567 save_control_configs(false);
6568 }
6569 else //Cancel
6570 {
6571 Abtn = a;
6572 Bbtn = b;
6573 Sbtn = s;
6574 Lbtn = l;
6575 Rbtn = r;
6576 Mbtn = m;
6577 Pbtn = p;
6578 Exbtn1 = ex1;
6579 Exbtn2 = ex2;
6580 Exbtn3 = ex3;
6581 Exbtn4 = ex4;
6582 DUbtn = up;
6583 DDbtn = down;
6584 DLbtn = left;
6585 DRbtn = right;
6586 joystick_index = joy;
6587 js_stick_1_x_stick = stick_1;
6588 js_stick_2_x_stick = stick_2;
6589 }
6590
6591 return D_O_K;
6592 }
6593
6594 int32_t onCheatKeys()
6595 {
6596 int32_t oldcheats[Cheat::Last][2];
6597 memcpy(oldcheats, cheatkeys, sizeof(cheatkeys));
6598
6599 bool done=false;
6600
6601 while(!done)
6602 {
6603 bool confirm = false;
6604 CheatKeysDialog(&confirm).show();
6605 if(confirm) // OK
6606 {
6607 std::vector<std::string> uniqueError;
6608 char buf[512];
6609 for(size_t q = 1; q < Cheat::Last; ++q)
6610 {
6611 if(cheatkeys[q][1] && !cheatkeys[q][0])
6612 {
6613 cheatkeys[q][0] = cheatkeys[q][1];
6614 cheatkeys[q][1] = 0;
6615 }
6616 }
6617 for(size_t q = 1; q < Cheat::Last; ++q)
6618 {
6619 if(!bindable_cheat((Cheat)q)) continue;
6620 for(size_t p = q+1; p < Cheat::Last; ++p)
6621 {
6622 if(!bindable_cheat((Cheat)p)) continue;
6623 for(size_t q2 = 0; q2 <= 1; ++q2)
6624 for(size_t p2 = 0; p2 <= 1; ++p2)
6625 {
6626 if(cheatkeys[q][q2] == cheatkeys[p][p2] && cheatkeys[q][q2] != 0)
6627 {
6628 uniqueError.push_back(fmt::format("'{}' ({}) conflicts with '{}' ({}) - both '{}'",
6629 cheat_to_string((Cheat)q), q2?"Alt":"Main",
6630 cheat_to_string((Cheat)p), p2?"Alt":"Main",
6631 get_keystr(cheatkeys[q][q2])));
6632 }
6633 }
6634 }
6635 }
6636 if(uniqueError.size() == 0)
6637 {
6638 done = true;
6639 save_cheatkeys();
6640 }
6641 else
6642 {
6643 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, 500,400, 2);
6644 box_out("Cannot have duplicate keybinds!"); box_eol();
6645 for(std::vector<std::string>::iterator it = uniqueError.begin();
6646 it != uniqueError.end(); ++it)
6647 {
6648 box_out((*it).c_str()); box_eol();
6649 }
6650 box_end(true);
6651 }
6652 }
6653 else // Cancel
6654 {
6655 memcpy(cheatkeys, oldcheats, sizeof(cheatkeys));
6656 done=true;
6657 }
6658 rest(1);
6659 }
6660
6661 return D_O_K;
6662 }
6663
6664 int32_t onSound()
6665 {
6666 if (get_qr(qr_OLD_SCRIPT_VOLUME))
6667 {
6668 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
6669 {
6670 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
6671 }
6672 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
6673 {
6674 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
6675 }
6676 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
6677 {
6678 emusic_volume = (int32_t)FFCore.usr_music_volume;
6679 }
6680 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
6681 {
6682 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
6683 }
6684 }
6685 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
6686 {
6687 pan_style = (int32_t)FFCore.usr_panstyle;
6688 }
6689
6690 int32_t m = midi_volume;
6691 int32_t e = emusic_volume;
6692 int32_t s = sfx_volume;
6693 int32_t p = pan_style;
6694 pan_style = vbound(pan_style,0,3);
6695
6696 sound_dlg[0].dp2=get_zc_font(font_lfont);
6697
6698 large_dialog(sound_dlg);
6699
6700 midi_dp[1] = sound_dlg[6].x;
6701 midi_dp[2] = sound_dlg[6].y;
6702 emus_dp[1] = sound_dlg[8].x;
6703 emus_dp[2] = sound_dlg[8].y;
6704 sfx_dp[1] = sound_dlg[10].x;
6705 sfx_dp[2] = sound_dlg[10].y;
6706 pan_dp[1] = sound_dlg[11].x;
6707 pan_dp[2] = sound_dlg[11].y;
6708 sound_dlg[15].d2 = (midi_volume==255) ? 32 : midi_volume>>3;
6709 sound_dlg[17].d2 = (emusic_volume==255) ? 32 : emusic_volume>>3;
6710 sound_dlg[19].d2 = (sfx_volume==255) ? 32 : sfx_volume>>3;
6711 sound_dlg[20].d2 = pan_style;
6712
6713 int32_t ret = do_zqdialog(sound_dlg,1);
6714
6715 if(ret==2)
6716 {
6717 master_volume(digi_volume,midi_volume);
6718 if (zcmusic)
6719 zcmusic_set_volume(zcmusic, emusic_volume);
6720
6721 int32_t temp_volume = sfx_volume;
6722 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
6723 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
6724 for(int32_t i=0; i<WAV_COUNT; ++i)
6725 {
6726 if(sfx_voice[i] >= 0)
6727 voice_set_volume(sfx_voice[i], temp_volume);
6728 }
6729 zc_set_config(sfx_sect,"midi",midi_volume);
6730 zc_set_config(sfx_sect,"sfx",sfx_volume);
6731 zc_set_config(sfx_sect,"emusic",emusic_volume);
6732 zc_set_config(sfx_sect,"pan",pan_style);
6733 }
6734 else
6735 {
6736 midi_volume = m;
6737 emusic_volume = e;
6738 sfx_volume = s;
6739 pan_style = p;
6740 }
6741
6742 return D_O_K;
6743 }
6744
6745 int32_t queding(char const* s1, char const* s2, char const* s3)
6746 {
6747 return jwin_alert("ZQuest Classic",s1,s2,s3,"&Yes","&No",'y','n',get_zc_font(font_lfont));
6748 }
6749
6750 int32_t onQuit()
6751 {
6752 if(Playing)
6753 {
6754 int32_t ret=0;
6755
6756 if(get_qr(qr_NOCONTINUE))
6757 {
6758 if(standalone_mode)
6759 {
6760 ret=queding("End current game?",
6761 "The continue screen is disabled; the game",
6762 "will be reloaded from the last save.");
6763 }
6764 else
6765 {
6766 ret=queding("End current game?",
6767 "The continue screen is disabled. You will",
6768 "be returned to the file select screen.");
6769 }
6770 }
6771 else
6772 ret=queding("End current game?",NULL,NULL);
6773
6774 if(ret==1)
6775 {
6776 disableClickToFreeze=false;
6777 Quit=qQUIT;
6778
6779 // Trying to evade a door repair charge?
6780 if(repaircharge)
6781 {
6782 game->change_drupy(-repaircharge);
6783 repaircharge=0;
6784 }
6785
6786 return D_CLOSE;
6787 }
6788 }
6789
6790 return D_O_K;
6791 }
6792
6793 int32_t onTryQuitMenu()
6794 {
6795 return onTryQuit(true);
6796 }
6797
6798 int32_t onTryQuit(bool inMenu)
6799 {
6800 if(Playing && !(GameFlags & GAMEFLAG_NO_F6))
6801 {
6802 if(active_cutscene.can_f6())
6803 {
6804 if(get_qr(qr_OLD_F6))
6805 {
6806 if(inMenu) onQuit();
6807 else /*if(!get_qr(qr_NOCONTINUE))*/ f_Quit(qQUIT);
6808 }
6809 else
6810 {
6811 disableClickToFreeze=false;
6812 GameFlags |= GAMEFLAG_TRYQUIT;
6813 }
6814 return D_CLOSE;
6815 }
6816 else active_cutscene.error();
6817 }
6818
6819 return D_O_K;
6820 }
6821
6822 int32_t onReset()
6823 {
6824 if(queding(" Reset system? ",NULL,NULL)==1)
6825 {
6826 disableClickToFreeze=false;
6827 Quit=qRESET;
6828 replay_quit();
6829 return D_CLOSE;
6830 }
6831
6832 return D_O_K;
6833 }
6834
6835 int32_t onExit()
6836 {
6837 if(queding(" Quit ZQuest Classic? ",NULL,NULL)==1)
6838 {
6839 Quit=qEXIT;
6840 return D_CLOSE;
6841 }
6842
6843 return D_O_K;
6844 }
6845
6846 int32_t onDebug()
6847 {
6848 if(debug_enabled)
6849 set_debug(!get_debug());
6850 return D_O_K;
6851 }
6852
6853 int32_t onHeartBeep()
6854 {
6855 heart_beep=!heart_beep;
6856 zc_set_config(cfg_sect,"heart_beep",heart_beep);
6857 return D_O_K;
6858 }
6859
6860 int32_t onSaveIndicator()
6861 {
6862 use_save_indicator = use_save_indicator ? 0 : 1;
6863 zc_set_config(cfg_sect,"save_indicator",use_save_indicator);
6864 return D_O_K;
6865 }
6866
6867 int32_t onEpilepsy()
6868 {
6869 if(jwin_alert3(
6870 "Epilepsy Flash Reduction",
6871 "Enabling this will reduce the intensity of flashing and screen wave effects.",
6872 "Disabling this will restore standard flash and wavy behaviour.",
6873 "Proceed?",
6874 "&Yes",
6875 "&No",
6876 NULL,
6877 'y',
6878 'n',
6879 0,
6880 get_zc_font(font_lfont)) == 1)
6881 {
6882 epilepsyFlashReduction = epilepsyFlashReduction ? 0 : 1;
6883 zc_set_config(cfg_sect,"epilepsy_flash_reduction",epilepsyFlashReduction);
6884 }
6885 return D_O_K;
6886 }
6887
6888 bool rc = false;
6889
6890 static DIALOG getnum_dlg[] =
6891 {
6892 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
6893 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
6894 { jwin_text_proc, 104, 104+4, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
6895 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
6896 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6897 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6898 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6899 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6900 };
6901
6902 int32_t getnumber(const char *prompt,int32_t initialval)
6903 {
6904 char buf[20];
6905 sprintf(buf,"%d",initialval);
6906 getnum_dlg[0].dp=(void *)prompt;
6907 getnum_dlg[0].dp2=get_zc_font(font_lfont);
6908 getnum_dlg[2].dp=buf;
6909
6910 large_dialog(getnum_dlg);
6911
6912 if(do_zqdialog(getnum_dlg,2)==3)
6913 return atoi(buf);
6914
6915 return initialval;
6916 }
6917
6918 int32_t onLife()
6919 {
6920 int value = vbound(getnumber("Life",game->get_life()),1,game->get_maxlife());
6921 cheats_enqueue(Cheat::Life, value);
6922 return D_O_K;
6923 }
6924
6925 int32_t onHeartC()
6926 {
6927 int max_life = vbound(getnumber("Heart Containers",game->get_maxlife()/game->get_hp_per_heart()),1,4095) * game->get_hp_per_heart();
6928 int life = vbound(getnumber("Life",game->get_life()/game->get_hp_per_heart()),1,max_life/game->get_hp_per_heart())*game->get_hp_per_heart();
6929 cheats_enqueue(Cheat::MaxLife, max_life);
6930 cheats_enqueue(Cheat::Life, life);
6931 return D_O_K;
6932 }
6933
6934 int32_t onMagicC()
6935 {
6936 int max_magic = vbound(getnumber("Magic Containers",game->get_maxmagic()/game->get_mp_per_block()),0,2047) * game->get_mp_per_block();
6937 int magic = vbound(getnumber("Magic",game->get_magic()/game->get_mp_per_block()),0,max_magic/game->get_mp_per_block())*game->get_mp_per_block();
6938 cheats_enqueue(Cheat::MaxMagic, max_magic);
6939 cheats_enqueue(Cheat::Magic, magic);
6940 return D_O_K;
6941 }
6942
6943 int32_t onRupies()
6944 {
6945 int value = vbound(getnumber("Rupees",game->get_rupies()),0,game->get_maxcounter(1));
6946 cheats_enqueue(Cheat::Rupies, value);
6947 return D_O_K;
6948 }
6949
6950 int32_t onMaxBombs()
6951 {
6952 int value = vbound(getnumber("Max Bombs",game->get_maxbombs()),0,0xFFFF);
6953 cheats_enqueue(Cheat::MaxBombs, value);
6954 cheats_enqueue(Cheat::Bombs, value);
6955 return D_O_K;
6956 }
6957
6958 int32_t onRefillLife()
6959 {
6960 cheats_enqueue(Cheat::Life, game->get_maxlife());
6961 return D_O_K;
6962 }
6963 int32_t onRefillMagic()
6964 {
6965 cheats_enqueue(Cheat::Magic, game->get_maxmagic());
6966 return D_O_K;
6967 }
6968 int32_t onClock()
6969 {
6970 cheats_enqueue(Cheat::Clock);
6971 return D_O_K;
6972 }
6973
6974 int32_t onQstPath()
6975 {
6976 char initial_path[2048];
6977 chop_path(qstdir);
6978 strcpy(initial_path, qstdir);
6979
6980 if (auto result = prompt_for_existing_folder("Quest File Directory", initial_path, "qst"))
6981 {
6982 char* path = result->data();
6983 chop_path(path);
6984 fix_filename_case(path);
6985 fix_filename_slashes(path);
6986 strcpy(qstdir,path);
6987 strcpy(qstpath,qstdir);
6988 zc_set_config("zeldadx","quest_dir",qstdir);
6989 flush_config_file();
6990 }
6991
6992 return D_O_K;
6993 }
6994
6995 #include "dialog/cheat_dialog.h"
6996 int32_t onCheat()
6997 {
6998 call_setcheat_dialog();
6999 game->set_cheat(maxcheat);
7000 if(cheat) game->did_cheat(true);
7001 return D_O_K;
7002 }
7003
7004 int32_t onCheatRupies()
7005 {
7006 cheats_enqueue(Cheat::Rupies, game->get_maxcounter(1));
7007 return D_O_K;
7008 }
7009
7010 int32_t onCheatArrows()
7011 {
7012 cheats_enqueue(Cheat::Arrows, game->get_maxarrows());
7013 return D_O_K;
7014 }
7015
7016 int32_t onCheatBombs()
7017 {
7018 cheats_enqueue(Cheat::Bombs, game->get_maxbombs(), game->get_maxcounter(6));
7019 return D_O_K;
7020 }
7021
7022 // *** screen saver
7023
7024 18318343 int32_t after_time()
7025 {
7026
1/2
✓ Branch 0 taken 18318343 times.
✗ Branch 1 not taken.
18318343 if(ss_enable == 0)
7027 return INT_MAX;
7028
7029
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18318343 times.
18318343 if(ss_after <= 0)
7030 return 5 * 60;
7031
7032
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18318343 times.
18318343 if(ss_after <= 3)
7033 return ss_after * 15 * 60;
7034
7035
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18318343 times.
18318343 if(ss_after <= 13)
7036 return (ss_after - 3) * 60 * 60;
7037
7038 18318343 return MAX_IDLE + 1;
7039 18318343 }
7040
7041 static const char *after_str[15] =
7042 {
7043 " 5 sec", "15 sec", "30 sec", "45 sec", " 1 min", " 2 min", " 3 min",
7044 " 4 min", " 5 min", " 6 min", " 7 min", " 8 min", " 9 min", "10 min",
7045 "Never"
7046 };
7047
7048 const char *after_list(int32_t index, int32_t *list_size)
7049 {
7050 if(index < 0)
7051 {
7052 *list_size = 15;
7053 return NULL;
7054 }
7055
7056 return after_str[index];
7057 }
7058
7059 336 static ListData after__list(after_list, &font);
7060
7061 static DIALOG scrsaver_dlg[] =
7062 {
7063 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7064 336 { jwin_win_proc, 32, 64, 256, 136, 0, 0, 0, D_EXIT, 0, 0, (void *) "Screen Saver Settings", NULL, NULL },
7065 336 { jwin_frame_proc, 42, 92, 236, 70, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
7066 336 { jwin_text_proc, 60, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Run After", NULL, NULL },
7067 336 { jwin_text_proc, 60, 128, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Speed", NULL, NULL },
7068 336 { jwin_text_proc, 60, 144, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Density", NULL, NULL },
7069 336 { jwin_droplist_proc, 144, 100, 96, 16, 0, 0, 0, 0, 0, 0, (void *) &after__list, NULL, NULL },
7070 336 { jwin_slider_proc, 144, 128, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7071 336 { jwin_slider_proc, 144, 144, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7072 336 { jwin_button_proc, 42, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7073 336 { jwin_button_proc, 124, 170, 72, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Preview", NULL, NULL },
7074 336 { jwin_button_proc, 218, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7075 336 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7076 336 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7077 };
7078
7079 int32_t onScreenSaver()
7080 {
7081 scrsaver_dlg[0].dp2=get_zc_font(font_lfont);
7082 int32_t oldcfgs[3];
7083 scrsaver_dlg[5].d1 = scrsaver_dlg[5].d2 = oldcfgs[0] = ss_after;
7084 scrsaver_dlg[6].d2 = oldcfgs[1] = ss_speed;
7085 scrsaver_dlg[7].d2 = oldcfgs[2] = ss_density;
7086
7087 large_dialog(scrsaver_dlg);
7088
7089 int32_t ret = do_zqdialog(scrsaver_dlg,-1);
7090
7091 if(ret == 8 || ret == 9)
7092 {
7093 ss_after = scrsaver_dlg[5].d1;
7094 ss_speed = scrsaver_dlg[6].d2;
7095 ss_density = scrsaver_dlg[7].d2;
7096 if(oldcfgs[0] != ss_after)
7097 zc_set_config(cfg_sect,"ss_after",ss_after);
7098 if(oldcfgs[1] != ss_speed)
7099 zc_set_config(cfg_sect,"ss_speed",ss_speed);
7100 if(oldcfgs[2] != ss_density)
7101 zc_set_config(cfg_sect,"ss_density",ss_density);
7102 }
7103
7104 if(ret == 9)
7105 // preview Screen Saver
7106 {
7107 clear_keybuf();
7108 Matrix(ss_speed, ss_density, 30);
7109 system_pal(true);
7110 sys_mouse();
7111 }
7112
7113 return D_O_K;
7114 }
7115
7116 /***** Menus *****/
7117
7118 enum
7119 {
7120 MENUID_GAME_LOADQUEST,
7121 MENUID_GAME_ENDGAME,
7122 };
7123
1/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
336 static NewMenu game_menu
7124 2688 {
7125
3/6
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 336 times.
✗ Branch 5 not taken.
336 { "&Continue","ESC", onContinue },
7126
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 {},
7127
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "L&oad Quest...", onCustomGame, MENUID_GAME_LOADQUEST },
7128
3/6
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 336 times.
✗ Branch 5 not taken.
336 { "&End Game","F6", onTryQuitMenu, MENUID_GAME_ENDGAME },
7129
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 {},
7130 #ifdef __EMSCRIPTEN__
7131 { "&Reset","F7", onReset },
7132 #elif defined(ALLEGRO_MACOSX)
7133 { "&Reset","F7", onReset },
7134 { "&Quit","F8", onExit },
7135 #else
7136
3/6
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 336 times.
✗ Branch 5 not taken.
336 { "&Reset","F9", onReset },
7137
3/6
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 336 times.
✗ Branch 5 not taken.
336 { "&Quit","F10", onExit },
7138 #endif
7139 };
7140
7141
1/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
336 static NewMenu snapshot_format_menu
7142 2352 {
7143
4/8
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 336 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 336 times.
✗ Branch 7 not taken.
336 { "&BMP", std::bind(onSetSnapshotFormat, ssfmtBMP) },
7144
4/8
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 336 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 336 times.
✗ Branch 7 not taken.
336 { "&GIF", std::bind(onSetSnapshotFormat, ssfmtGIF) },
7145
4/8
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 336 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 336 times.
✗ Branch 7 not taken.
336 { "&JPG", std::bind(onSetSnapshotFormat, ssfmtJPG) },
7146
4/8
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 336 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 336 times.
✗ Branch 7 not taken.
336 { "&PNG", std::bind(onSetSnapshotFormat, ssfmtPNG) },
7147
4/8
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 336 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 336 times.
✗ Branch 7 not taken.
336 { "PC&X", std::bind(onSetSnapshotFormat, ssfmtPCX) },
7148
4/8
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 336 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 336 times.
✗ Branch 7 not taken.
336 { "&TGA", std::bind(onSetSnapshotFormat, ssfmtTGA) },
7149 };
7150
7151
1/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
336 static NewMenu controls_menu
7152 1344 {
7153
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Key&board...", onKeyboard },
7154
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Gamepad...", onGamepad },
7155
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Cheat Keys...", onCheatKeys },
7156 };
7157
7158
1/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
336 static NewMenu name_entry_mode_menu
7159 1344 {
7160
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Keyboard", onKeyboardEntry },
7161
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Letter Grid", onLetterGridEntry },
7162
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Extended Letter Grid", onExtLetterGridEntry },
7163 };
7164
7165 static void set_controls_menu_active()
7166 {
7167
7168 }
7169
7170 enum
7171 {
7172 MENUID_WINDOW_LOCK_ASPECT,
7173 MENUID_WINDOW_LOCK_INTSCALE,
7174 MENUID_WINDOW_SAVE_SIZE,
7175 MENUID_WINDOW_SAVE_POS,
7176 MENUID_WINDOW_STRETCH,
7177 };
7178
1/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
336 static NewMenu window_menu
7179 2016 {
7180
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Lock Aspect Ratio", onDragAspect, MENUID_WINDOW_LOCK_ASPECT },
7181
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Lock Integer Scale", onIntegerScaling, MENUID_WINDOW_LOCK_INTSCALE },
7182
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Save Size Changes", onSaveDragResize, MENUID_WINDOW_SAVE_SIZE },
7183
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Save Position Changes", onWinPosSave, MENUID_WINDOW_SAVE_POS },
7184
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Stretch Game Area", onStretchGame, MENUID_WINDOW_STRETCH },
7185 };
7186 void call_zc_options_dlg();
7187 enum
7188 {
7189 MENUID_OPTIONS_PAUSE_BG,
7190 MENUID_OPTIONS_EPILEPSYPROT,
7191 };
7192
1/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
336 static NewMenu options_menu
7193 2352 {
7194
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Name &Entry Mode", &name_entry_mode_menu },
7195
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "S&napshot Format", &snapshot_format_menu },
7196
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Window Settings", &window_menu },
7197
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Epilepsy Flash Reduction", onEpilepsy, MENUID_OPTIONS_EPILEPSYPROT },
7198
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Pause In Background", onPauseInBackground, MENUID_OPTIONS_PAUSE_BG },
7199
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "More Options", call_zc_options_dlg },
7200 };
7201 enum
7202 {
7203 MENUID_SETTINGS_CONTROLS,
7204 MENUID_SETTINGS_CAPFPS,
7205 MENUID_SETTINGS_SHOWFPS,
7206 MENUID_SETTINGS_SHOWTIME,
7207 MENUID_SETTINGS_CLICK_FREEZE,
7208 MENUID_SETTINGS_TRANSLAYERS,
7209 MENUID_SETTINGS_NESQUIT,
7210 MENUID_SETTINGS_VOLKEYS,
7211 MENUID_SETTINGS_HEARTBEEP,
7212 MENUID_SETTINGS_SAVEINDICATOR,
7213 MENUID_SETTINGS_DEBUG,
7214 };
7215
1/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
336 static NewMenu settings_menu
7216 5712 {
7217
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Sound...", onSound },
7218
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "C&ontrols", &controls_menu, MENUID_SETTINGS_CONTROLS },
7219
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 {},
7220
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Options", &options_menu },
7221
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 {},
7222
3/6
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 336 times.
✗ Branch 5 not taken.
336 { "&Cap FPS","F1", onThrottleFPS, MENUID_SETTINGS_CAPFPS },
7223
3/6
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 336 times.
✗ Branch 5 not taken.
336 { "Show &FPS","F2", onShowFPS, MENUID_SETTINGS_SHOWFPS },
7224
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Show &Time", onShowTime, MENUID_SETTINGS_SHOWTIME },
7225
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Click to Freeze", onClickToFreeze, MENUID_SETTINGS_CLICK_FREEZE },
7226
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Cont. &Heart Beep", onHeartBeep, MENUID_SETTINGS_HEARTBEEP },
7227
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Show Trans. &Layers", onTransLayers, MENUID_SETTINGS_TRANSLAYERS },
7228
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Up+A+B To &Quit", onNESquit, MENUID_SETTINGS_NESQUIT },
7229
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Volume &Keys", onVolKeys, MENUID_SETTINGS_VOLKEYS },
7230
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Sa&ve Indicator", onSaveIndicator, MENUID_SETTINGS_SAVEINDICATOR },
7231
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 {},
7232
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Debu&g", onDebug, MENUID_SETTINGS_DEBUG },
7233 };
7234
7235 enum
7236 {
7237 MENUID_MISC_FULLSCREEN,
7238 MENUID_MISC_VIDMODE,
7239 MENUID_MISC_QUEST_INFO,
7240 MENUID_MISC_QUEST_DIR,
7241 MENUID_MISC_CONSOLE,
7242 MENUID_MISC_CLEAR_CONSOLE_ON_LOAD,
7243 };
7244
1/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
336 static NewMenu misc_menu
7245 5040 {
7246
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&About...", onAbout },
7247 // TODO: re-enable, but: 1) do not use a bitmap thing that is hard to update 2) update names and 3) don't use the Z-word.
7248 // { "&Credits...", onCredits },
7249
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Fullscreen", onFullscreenMenu, MENUID_MISC_FULLSCREEN },
7250
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Video Mode...", onVidMode, MENUID_MISC_VIDMODE },
7251
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 {},
7252
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Quest Info...", onQuest, MENUID_MISC_QUEST_INFO },
7253
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Quest &MIDI Info...", onMIDICredits },
7254
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Quest &Directory...", onQstPath, MENUID_MISC_QUEST_DIR },
7255
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 {},
7256
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Take &Snapshot F12", onSnapshot },
7257
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Sc&reen Saver...", onScreenSaver },
7258
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Save ZC Configuration", OnSaveZCConfig },
7259
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Show Console", onConsole, MENUID_MISC_CONSOLE },
7260
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Clear Console on Qst Load", onClrConsoleOnLoad, MENUID_MISC_CLEAR_CONSOLE_ON_LOAD },
7261
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Clear Directory Cache", OnnClearQuestDir },
7262 };
7263
7264 enum
7265 {
7266 MENUID_REFILL_ARROWS,
7267 };
7268
1/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
336 static NewMenu refill_menu
7269 2016 {
7270
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Life", onRefillLife },
7271
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Magic", onRefillMagic },
7272
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Bombs", onCheatBombs },
7273
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Rupees", onCheatRupies },
7274
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Arrows", onCheatArrows, MENUID_REFILL_ARROWS },
7275 };
7276
7277 enum
7278 {
7279 MENUID_SHOW_L0,
7280 MENUID_SHOW_L1,
7281 MENUID_SHOW_L2,
7282 MENUID_SHOW_L3,
7283 MENUID_SHOW_L4,
7284 MENUID_SHOW_L5,
7285 MENUID_SHOW_L6,
7286 MENUID_SHOW_OVER,
7287 MENUID_SHOW_PUSH,
7288 MENUID_SHOW_FFC,
7289 MENUID_SHOW_SPR,
7290 MENUID_SHOW_SCRIPTNAME,
7291 MENUID_SHOW_SOLIDITY,
7292 MENUID_SHOW_HITBOX,
7293 MENUID_SHOW_EFFECT,
7294 };
7295
1/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
336 static NewMenu show_menu
7296 6384 {
7297
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Combos", onShowLayer0, MENUID_SHOW_L0 },
7298
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Layer 1", onShowLayer1, MENUID_SHOW_L1 },
7299
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Layer 2", onShowLayer2, MENUID_SHOW_L2 },
7300
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Layer 3", onShowLayer3, MENUID_SHOW_L3 },
7301
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Layer 4", onShowLayer4, MENUID_SHOW_L4 },
7302
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Layer 5", onShowLayer5, MENUID_SHOW_L5 },
7303
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Layer 6", onShowLayer6, MENUID_SHOW_L6 },
7304
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Overhead Combos", onShowLayerO, MENUID_SHOW_OVER },
7305
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Push Blocks", onShowLayerP, MENUID_SHOW_PUSH },
7306
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Freeform Combos", onShowLayerF, MENUID_SHOW_FFC },
7307
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Sprites", onShowLayerS, MENUID_SHOW_SPR },
7308
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 {},
7309
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Current FFC Scripts", onShowFFScripts, MENUID_SHOW_SCRIPTNAME },
7310
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 {},
7311
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Walkability", onShowLayerW, MENUID_SHOW_SOLIDITY },
7312
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Hitboxes", onShowHitboxes, MENUID_SHOW_HITBOX },
7313
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Effects", onShowLayerE, MENUID_SHOW_EFFECT },
7314
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Info Opacity", onShowInfoOpacity },
7315 };
7316
7317 enum
7318 {
7319 MENUID_CHEAT_CHOP_L1,
7320 MENUID_CHEAT_CHOP_L2,
7321 MENUID_CHEAT_CHOP_L3,
7322 MENUID_CHEAT_CHOP_L4,
7323 MENUID_CHEAT_INVULN,
7324 MENUID_CHEAT_NOCLIP,
7325 MENUID_CHEAT_IGNORESV,
7326 MENUID_CHEAT_GOFAST,
7327 };
7328
1/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
336 static NewMenu cheat_menu
7329 5712 {
7330
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Set &Cheat", onCheat },
7331
1/2
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
336 { MENUID_CHEAT_CHOP_L1 },
7332
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Re&fill", &refill_menu },
7333
1/2
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
336 { MENUID_CHEAT_CHOP_L2 },
7334
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Invincible", onClock, MENUID_CHEAT_INVULN },
7335
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Ma&x Bombs...", onMaxBombs },
7336
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Heart Containers...", onHeartC },
7337
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Magic Containers...", onMagicC },
7338
1/2
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
336 { MENUID_CHEAT_CHOP_L3 },
7339
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Hero Data...", onCheatConsole },
7340
1/2
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
336 { MENUID_CHEAT_CHOP_L4 },
7341
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Walk Through &Walls", onNoWalls, MENUID_CHEAT_NOCLIP },
7342
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Hero Ignores Side&view", onIgnoreSideview, MENUID_CHEAT_IGNORESV },
7343
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Quick Movement", onGoFast, MENUID_CHEAT_GOFAST },
7344
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Kill All Enemies", onKillCheat },
7345
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Trigger &Secrets", onSecretsCheat },
7346
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Trigger Secrets Perm", onSecretsCheatPerm },
7347
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Show/Hide Layer", &show_menu },
7348
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "Toggle &Light", onLightSwitch },
7349
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Goto Location...", onGoTo },
7350 };
7351
7352 #if DEVLEVEL > 0
7353 int32_t devLogging();
7354 int32_t devDebug();
7355 int32_t devTimestmp();
7356 #if DEVLEVEL > 1
7357 int32_t setCheat();
7358 #endif //DEVLEVEL > 1
7359 enum
7360 {
7361 MENUID_DEV_LOGGING,
7362 MENUID_DEV_DEBUG,
7363 MENUID_DEV_TIMESTAMP,
7364 MENUID_DEV_SETCHEAT,
7365 };
7366 static NewMenu dev_menu
7367 {
7368 { "&Force Error Log", devLogging, MENUID_DEV_LOGGING },
7369 // { "&Extra Debug Log", devDebug, MENUID_DEV_DEBUG },
7370 { "&Timestamp Log", devTimestmp, MENUID_DEV_TIMESTAMP },
7371 #if DEVLEVEL > 1
7372 {},
7373 { "Set &Cheat", setCheat, MENUID_DEV_SETCHEAT },
7374 #endif //DEVLEVEL > 1
7375 };
7376 int32_t devLogging()
7377 {
7378 dev_logging = !dev_logging;
7379 dev_menu.select_uid(MENUID_DEV_LOGGING, dev_logging);
7380 return D_O_K;
7381 }
7382 // int32_t devDebug()
7383 // {
7384 // dev_debug = !dev_debug;
7385 // dev_menu.select_uid(MENUID_DEV_DEBUG, dev_debug);
7386 // dev_menu[dv_dbg].flags = dev_debug ? D_SELECTED : 0;
7387 // return D_O_K;
7388 // }
7389 int32_t devTimestmp()
7390 {
7391 dev_timestmp = !dev_timestmp;
7392 dev_menu.select_uid(MENUID_DEV_TIMESTAMP, dev_timestmp);
7393 return D_O_K;
7394 }
7395 #if DEVLEVEL > 1
7396 int32_t setCheat()
7397 {
7398 cheat = (vbound(getnumber("Cheat Level",cheat), 0, 4));
7399 return D_O_K;
7400 }
7401 #endif //DEVLEVEL > 1
7402 #endif //DEVLEVEL > 0
7403
7404 enum
7405 {
7406 MENUID_PLAYER_CHEAT,
7407 };
7408
1/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
336 TopMenu the_player_menu
7409 2016 {
7410
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Game", &game_menu },
7411
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Settings", &settings_menu },
7412
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Cheat", &cheat_menu, MENUID_PLAYER_CHEAT, true },
7413
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&Replay", &replay_menu },
7414
2/4
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
✗ Branch 3 not taken.
336 { "&ZC", &misc_menu },
7415 #if DEVLEVEL > 0
7416 { "&Dev", &dev_menu },
7417 #endif
7418 };
7419
7420 int32_t onPauseInBackground()
7421 {
7422 if(jwin_alert3(
7423 "Toggle Pause In Background",
7424 "This action will change whether ZC Player pauses when the window loses focus.",
7425 "",
7426 "Proceed?",
7427 "&Yes",
7428 "&No",
7429 NULL,
7430 'y',
7431 'n',
7432 0,
7433 get_zc_font(font_lfont)) == 1)
7434 {
7435 pause_in_background = pause_in_background ? 0 : 1;
7436 zc_set_config("zeldadx","pause_in_background", pause_in_background);
7437 int switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7438 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7439 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7440 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7441 }
7442 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7443 return D_O_K;
7444 }
7445
7446 int32_t onKeyboardEntry()
7447 {
7448 NameEntryMode=0;
7449 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7450 return D_O_K;
7451 }
7452
7453 int32_t onLetterGridEntry()
7454 {
7455 NameEntryMode=1;
7456 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7457 return D_O_K;
7458 }
7459
7460 int32_t onExtLetterGridEntry()
7461 {
7462 NameEntryMode=2;
7463 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7464 return D_O_K;
7465 }
7466
7467 static BITMAP* oldscreen;
7468 int32_t onFullscreenMenu()
7469 {
7470 PALETTE oldpal;
7471 get_palette(oldpal);
7472
7473 fullscreen = !fullscreen;
7474 all_toggle_fullscreen(fullscreen);
7475 zc_set_config("zeldadx","fullscreen",fullscreen);
7476
7477 zc_set_palette(oldpal);
7478 gui_mouse_focus=0;
7479 extern int32_t switch_type;
7480 switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7481 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7482 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7483 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7484 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7485 misc_menu.select_uid(MENUID_MISC_VIDMODE, isFullScreen());
7486
7487 return D_O_K;
7488 }
7489
7490 246 void fix_menu()
7491 {
7492
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 246 times.
246 if(!debug_enabled)
7493 246 settings_menu.chop_index = 13;
7494 246 }
7495
7496 int32_t onSetSnapshotFormat(SnapshotType format)
7497 {
7498 SnapshotFormat = format;
7499 zc_set_config("zeldadx", "snapshot_format", format);
7500 snapshot_format_menu.select_only_index(format);
7501 return D_O_K;
7502 }
7503
7504
7505 void color_layer(RGB *src,RGB *dest,char r,char g,char b,char pos,int32_t from,int32_t to)
7506 {
7507 PALETTE tmp;
7508
7509 for(int32_t i=0; i<256; i++)
7510 {
7511 tmp[i].r=r;
7512 tmp[i].g=g;
7513 tmp[i].b=b;
7514 }
7515
7516 fade_interpolate(src,tmp,dest,pos,from,to);
7517 }
7518
7519 55 void system_pal(bool force)
7520 {
7521
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
55 if(is_sys_pal && !force) return;
7522 55 is_sys_pal = true;
7523 55 load_colorset(gui_colorset, syspal, jwin_a5_colors);
7524 55 hw_palette = &syspal;
7525 55 update_hw_pal = true;
7526 55 }
7527
7528 static uint32_t entered_sys_pal = 0;
7529 55 void enter_sys_pal()
7530 {
7531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(is_sys_pal)
7532 {
7533 if(entered_sys_pal)
7534 ++entered_sys_pal;
7535 return;
7536 }
7537 55 sys_mouse();
7538 55 system_pal(true);
7539 55 ++entered_sys_pal;
7540 55 }
7541 55 void exit_sys_pal()
7542 {
7543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(entered_sys_pal)
7544 {
7545
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 if(!--entered_sys_pal)
7546 {
7547 55 game_pal();
7548 55 game_mouse();
7549 55 }
7550 55 }
7551 55 }
7552
7553 void switch_out_callback()
7554 {
7555 if (pause_in_background && !MenuOpen)
7556 {
7557 System();
7558 }
7559 }
7560
7561 void switch_in_callback()
7562 {
7563 }
7564
7565 1080 void game_pal()
7566 {
7567 1080 is_sys_pal = false;
7568 1080 entered_sys_pal = 0;
7569 1080 hw_palette = &RAMpal;
7570 1080 update_hw_pal = true;
7571 1080 }
7572
7573 static char bar_str[] = "";
7574
7575 55 void music_pause()
7576 {
7577 //al_pause_duh(tmplayer);
7578 55 zcmusic_pause(zcmusic, ZCM_PAUSE);
7579
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(zcmixer->oldtrack)
7580 zcmusic_pause(zcmixer->oldtrack, ZCM_PAUSE);
7581 55 zc_midi_pause();
7582 55 }
7583
7584 void music_resume()
7585 {
7586 //al_resume_duh(tmplayer);
7587 zcmusic_pause(zcmusic, ZCM_RESUME);
7588 if (zcmixer->oldtrack)
7589 zcmusic_pause(zcmixer->oldtrack, ZCM_RESUME);
7590 zc_midi_resume();
7591 }
7592
7593 7759 void music_stop()
7594 {
7595 //al_stop_duh(tmplayer);
7596 //unload_duh(tmusic);
7597 //tmusic=NULL;
7598 //tmplayer=NULL;
7599 7759 zcmusic_stop(zcmusic);
7600 7759 zcmusic_unload_file(zcmusic);
7601
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7759 times.
7759 if (zcmixer->oldtrack)
7602 {
7603 zcmusic_stop(zcmixer->oldtrack);
7604 zcmusic_unload_file(zcmixer->oldtrack);
7605 }
7606 7759 zcmixer->newtrack = NULL;
7607 7759 zc_stop_midi();
7608 7759 currmidi=-1;
7609 7759 }
7610
7611 bool reload_fonts = false;
7612 void System()
7613 {
7614 mouse_down = gui_mouse_b();
7615 music_pause();
7616 pause_all_sfx();
7617 MenuOpen = true;
7618 enter_sys_pal();
7619 // FONT *oldfont=font;
7620 // font=tfont;
7621
7622 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7623 misc_menu.disable_uid(MENUID_MISC_VIDMODE, isFullScreen());
7624
7625 #if DEVLEVEL > 1
7626 dev_menu.disable_uid(MENUID_DEV_SETCHEAT, !Playing);
7627 #endif
7628 game_menu.disable_uid(MENUID_GAME_LOADQUEST, get_unset_save_slot());
7629 game_menu.disable_uid(MENUID_GAME_ENDGAME, !Playing);
7630 misc_menu.disable_uid(MENUID_MISC_QUEST_INFO, !Playing);
7631 misc_menu.disable_uid(MENUID_MISC_QUEST_DIR, Playing);
7632 clear_keybuf();
7633
7634 clear_bitmap(menu_bmp);
7635 oldscreen = screen;
7636 screen = menu_bmp;
7637
7638 the_player_menu.reset_state();
7639 the_player_menu.position(0, 0);
7640
7641 bool running = true;
7642 bool esc = key[KEY_ESC] || cMbtn();
7643 bool autopop = esc;
7644 do
7645 {
7646 if(reload_fonts)
7647 {
7648 init_custom_fonts();
7649 clear_bitmap(menu_bmp);
7650 broadcast_dialog_message(MSG_DRAW, 0);
7651 reload_fonts = false;
7652 }
7653 if(handle_close_btn_quit())
7654 break;
7655
7656 //update submenus
7657 {
7658 settings_menu.disable_uid(MENUID_SETTINGS_CONTROLS, replay_is_replaying());
7659 settings_menu.select_uid(MENUID_SETTINGS_CAPFPS, Throttlefps);
7660 settings_menu.select_uid(MENUID_SETTINGS_SHOWFPS, ShowFPS);
7661 settings_menu.select_uid(MENUID_SETTINGS_SHOWTIME, ShowGameTime);
7662 settings_menu.select_uid(MENUID_SETTINGS_CLICK_FREEZE, ClickToFreeze);
7663 settings_menu.select_uid(MENUID_SETTINGS_TRANSLAYERS, TransLayers);
7664 settings_menu.select_uid(MENUID_SETTINGS_NESQUIT, NESquit);
7665 settings_menu.select_uid(MENUID_SETTINGS_VOLKEYS, volkeys);
7666
7667 window_menu.select_uid(MENUID_WINDOW_LOCK_ASPECT, DragAspect);
7668 window_menu.select_uid(MENUID_WINDOW_LOCK_INTSCALE, scaleForceInteger);
7669 window_menu.select_uid(MENUID_WINDOW_SAVE_SIZE, SaveDragResize);
7670 window_menu.select_uid(MENUID_WINDOW_SAVE_POS, SaveWinPos);
7671 window_menu.select_uid(MENUID_WINDOW_STRETCH, stretchGame);
7672
7673 options_menu.select_uid(MENUID_OPTIONS_EPILEPSYPROT, epilepsyFlashReduction);
7674 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7675
7676 name_entry_mode_menu.select_only_index(NameEntryMode);
7677
7678 misc_menu.select_uid(MENUID_MISC_CONSOLE, console_enabled);
7679 misc_menu.select_uid(MENUID_MISC_CLEAR_CONSOLE_ON_LOAD, clearConsoleOnLoad);
7680
7681 bool nocheat = (replay_is_replaying() || !Playing
7682 || (!maxcheat && !zcheats.flags && !get_debug() && DEVLEVEL < 2 && !zqtesting_mode && !devpwd()));
7683 the_player_menu.disable_uid(MENUID_PLAYER_CHEAT, nocheat);
7684 refill_menu.disable_uid(MENUID_REFILL_ARROWS, !get_qr(qr_TRUEARROWS));
7685 cheat_menu.chop_index.reset();
7686 if(cheat < 4)
7687 cheat_menu.chop_index = cheat_menu.ind_at(MENUID_CHEAT_CHOP_L1+cheat);
7688 cheat_menu.select_uid(MENUID_CHEAT_INVULN, getClock());
7689 cheat_menu.select_uid(MENUID_CHEAT_NOCLIP, toogam);
7690 cheat_menu.select_uid(MENUID_CHEAT_IGNORESV, ignoreSideview);
7691 cheat_menu.select_uid(MENUID_CHEAT_GOFAST, gofast);
7692
7693 show_menu.select_uid(MENUID_SHOW_L0, show_layer_0);
7694 show_menu.select_uid(MENUID_SHOW_L1, show_layer_1);
7695 show_menu.select_uid(MENUID_SHOW_L2, show_layer_2);
7696 show_menu.select_uid(MENUID_SHOW_L3, show_layer_3);
7697 show_menu.select_uid(MENUID_SHOW_L4, show_layer_4);
7698 show_menu.select_uid(MENUID_SHOW_L5, show_layer_5);
7699 show_menu.select_uid(MENUID_SHOW_L6, show_layer_6);
7700 show_menu.select_uid(MENUID_SHOW_OVER, show_layer_over);
7701 show_menu.select_uid(MENUID_SHOW_PUSH, show_layer_push);
7702 show_menu.select_uid(MENUID_SHOW_SPR, show_sprites);
7703 show_menu.select_uid(MENUID_SHOW_FFC, show_ffcs);
7704 show_menu.select_uid(MENUID_SHOW_SOLIDITY, show_walkflags);
7705 show_menu.select_uid(MENUID_SHOW_SCRIPTNAME, show_ff_scripts);
7706 show_menu.select_uid(MENUID_SHOW_HITBOX, show_hitboxes);
7707 show_menu.select_uid(MENUID_SHOW_EFFECT, show_effectflags);
7708
7709 settings_menu.select_uid(MENUID_SETTINGS_HEARTBEEP, heart_beep);
7710 settings_menu.select_uid(MENUID_SETTINGS_SAVEINDICATOR, use_save_indicator);
7711
7712 replay_menu.by_uid(MENUID_REPLAY_STOP)->text = fmt::format("Stop {}",
7713 replay_get_mode() == ReplayMode::Record ? "recording" : "replaying");
7714
7715 replay_menu.select_uid(MENUID_REPLAY_RECORDNEW, zc_get_config("zeldadx", "replay_new_saves", false));
7716 #ifdef HAS_CURL
7717 replay_menu.select_uid(MENUID_REPLAY_AUTOUPLOAD, replay_upload_auto_enabled());
7718 #endif
7719 replay_menu.disable_uid(MENUID_REPLAY_STOP, !replay_is_active());
7720 replay_menu.disable_uid(MENUID_REPLAY_SAVE, replay_get_mode() != ReplayMode::Record);
7721 replay_menu.select_uid(MENUID_REPLAY_SNAP_ALL, replay_is_snapshot_all_frames());
7722
7723 snapshot_format_menu.select_only_index(SnapshotFormat);
7724 }
7725
7726 if(debug_enabled)
7727 settings_menu.select_uid(MENUID_SETTINGS_DEBUG, get_debug());
7728
7729 if(autopop)
7730 clear_keybuf();
7731 the_player_menu.run(true);
7732 if(autopop)
7733 {
7734 the_player_menu.pop_sub(0, &the_player_menu);
7735 the_player_menu.draw(screen, the_player_menu.hovered_ind());
7736 autopop = false;
7737 update_hw_screen();
7738 }
7739
7740 update_hw_screen();
7741
7742 auto mb = gui_mouse_b();
7743 if(XOR(mb, mouse_down))
7744 {
7745 if(!the_player_menu.has_mouse())
7746 if(mb)
7747 break;
7748 mouse_down = mb;
7749 }
7750
7751 if(input_idle(true) > after_time())
7752 // run Screeen Saver
7753 {
7754 // Screen saver enabled for now.
7755 clear_keybuf();
7756 Matrix(ss_speed, ss_density, 0);
7757 system_pal(true);
7758 sys_mouse();
7759 }
7760
7761 poll_keyboard();
7762 if(esc)
7763 {
7764 if(!key[KEY_ESC])
7765 esc = false;
7766 }
7767
7768 if(keypressed() && !CHECK_ALT) //System hotkeys
7769 {
7770 auto c = peekkey();
7771 bool eatkey = true;
7772 switch(c>>8)
7773 {
7774 //Spare keys used by the menu
7775 case KEY_UP:
7776 case KEY_DOWN:
7777 case KEY_LEFT:
7778 case KEY_RIGHT:
7779 eatkey = false;
7780 break;
7781 case KEY_F1:
7782 onThrottleFPS();
7783 break;
7784 case KEY_F2:
7785 onShowFPS();
7786 break;
7787 case KEY_F6:
7788 onTryQuitMenu();
7789 break;
7790 #ifndef ALLEGRO_MACOSX
7791 case KEY_F9:
7792 onReset();
7793 break;
7794 case KEY_F10:
7795 onExit();
7796 break;
7797 #else
7798 case KEY_F7:
7799 onReset();
7800 break;
7801 case KEY_F8:
7802 onExit();
7803 break;
7804 #endif
7805 case KEY_F12:
7806 onSnapshot();
7807 break;
7808 case KEY_TAB:
7809 onDebug();
7810 break;
7811 case KEY_ESC:
7812 if(!esc)
7813 running = false;
7814 break;
7815 }
7816 if(eatkey)
7817 readkey();
7818 }
7819 if(Quit || (GameFlags & GAMEFLAG_TRYQUIT))
7820 break;
7821 }
7822 while(running);
7823
7824 screen = oldscreen;
7825
7826 mouse_down=gui_mouse_b();
7827 MenuOpen = false;
7828 if(Quit)
7829 {
7830 kill_sfx();
7831 music_stop();
7832 update_hw_screen();
7833 }
7834 else
7835 {
7836 music_resume();
7837 resume_all_sfx();
7838
7839 if(rc)
7840 ringcolor(false);
7841 }
7842 exit_sys_pal();
7843
7844 eat_buttons();
7845
7846 rc=false;
7847 clear_keybuf();
7848
7849 zc_init_apply_cheat_delta();
7850 }
7851
7852 246 void fix_dialogs()
7853 {
7854 246 jwin_center_dialog(about_dlg);
7855 246 jwin_center_dialog(gamepad_dlg);
7856 246 jwin_center_dialog(credits_dlg);
7857 246 jwin_center_dialog(gamemode_dlg);
7858 246 jwin_center_dialog(getnum_dlg);
7859 246 jwin_center_dialog(goto_dlg);
7860 246 jwin_center_dialog(keyboard_control_dlg);
7861 246 jwin_center_dialog(midi_dlg);
7862 246 jwin_center_dialog(quest_dlg);
7863 246 jwin_center_dialog(scrsaver_dlg);
7864 246 jwin_center_dialog(sound_dlg);
7865 246 jwin_center_dialog(triforce_dlg);
7866 246 }
7867
7868 4262 INLINE int32_t mixvol(int32_t v1,int32_t v2)
7869 {
7870
3/4
✓ Branch 0 taken 4262 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4240 times.
✓ Branch 3 taken 22 times.
4262 return (zc_min(v1,255)*zc_min(v2,255)) >> 8;
7871 }
7872
7873 289 int32_t get_emusic_volume()
7874 {
7875 289 int32_t temp_volume = emusic_volume;
7876
2/4
✓ Branch 0 taken 289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 289 times.
✗ Branch 3 not taken.
289 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
7877 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
7878
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 289 times.
289 if (!zcmusic)
7879 289 return temp_volume;
7880 return (temp_volume * zcmusic->fadevolume) / 10000;
7881 289 }
7882
7883 int32_t get_zcmusicpos()
7884 {
7885 int32_t debugtracething = zcmusic_get_curpos(zcmusic);
7886 return debugtracething;
7887 return 0;
7888 }
7889
7890 void set_zcmusicpos(int32_t position)
7891 {
7892 zcmusic_set_curpos(zcmusic, position);
7893 }
7894
7895 void set_zcmusicspeed(int32_t speed)
7896 {
7897 zcmusic_set_speed(zcmusic, speed);
7898 }
7899
7900 int32_t get_zcmusiclen()
7901 {
7902 return zcmusic_get_length(zcmusic);
7903 }
7904
7905 3 void set_zcmusicloop(double start, double end)
7906 {
7907 3 zcmusic_set_loop(zcmusic, start, end);
7908 3 }
7909
7910 64156 void jukebox(int32_t index,int32_t loop)
7911 {
7912
1/2
✓ Branch 0 taken 64156 times.
✗ Branch 1 not taken.
64156 if (is_headless())
7913 64156 return;
7914
7915 music_stop();
7916
7917 if(index<0) index=MAXMIDIS-1;
7918
7919 if(index>=MAXMIDIS) index=0;
7920
7921 music_stop();
7922
7923 // Allegro's DIGMID driver (the one normally used on on Linux) gets
7924 // stuck notes when a song stops. This fixes it.
7925 if(strcmp(midi_driver->name, "DIGMID")==0)
7926 zc_set_volume(0, 0);
7927
7928 zc_set_volume(-1, mixvol(tunes[index].volume, midi_volume >>1));
7929 zc_play_midi(tunes[index].data,loop);
7930
7931 if(tunes[index].start>0)
7932 zc_midi_seek(tunes[index].start);
7933
7934 midi_loop_start = tunes[index].loop_start;
7935 midi_loop_end = tunes[index].loop_end;
7936
7937 currmidi=index;
7938 master_volume(digi_volume, midi_volume);
7939 //midi_paused=false;
7940 64156 }
7941
7942 64156 void jukebox(int32_t index)
7943 {
7944
1/2
✓ Branch 0 taken 64156 times.
✗ Branch 1 not taken.
64156 if(index<0) index=MAXMIDIS-1;
7945
7946
1/2
✓ Branch 0 taken 64156 times.
✗ Branch 1 not taken.
64156 if(index>=MAXMIDIS) index=0;
7947
7948 // do nothing if it's already playing
7949
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 64156 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64156 if(index==currmidi && midi_pos>=0)
7950 {
7951 return;
7952 }
7953
7954 64156 jukebox(index,tunes[index].loop);
7955 64156 }
7956
7957 100 void play_DmapMusic()
7958 {
7959
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if (is_headless())
7960 100 return;
7961
7962 static char tfile[2048];
7963 static int32_t ttrack=0;
7964 bool domidi=false;
7965
7966 int32_t fadeoutframes = 0;
7967 if (zcmusic != NULL)
7968 fadeoutframes = zcmusic->fadeoutframes;
7969
7970 if(DMaps[currdmap].tmusic[0]!=0)
7971 {
7972 if(zcmusic==NULL ||
7973 strcmp(zcmusic->filename,DMaps[currdmap].tmusic)!=0 ||
7974 (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[currdmap].tmusictrack))
7975 {
7976 if (DMaps[currdmap].tmusic_xfade_in > 0 || fadeoutframes > 0)
7977 {
7978 if (play_enh_music_crossfade(DMaps[currdmap].tmusic, qstpath, DMaps[currdmap].tmusictrack, get_emusic_volume(), DMaps[currdmap].tmusic_xfade_in, fadeoutframes))
7979 {
7980 if (zcmusic != NULL)
7981 {
7982 zcmusic->fadeoutframes = DMaps[currdmap].tmusic_xfade_out;
7983 zcmusic_set_loop(zcmusic, double(DMaps[currdmap].tmusic_loop_start / 10000.0), double(DMaps[currdmap].tmusic_loop_end / 10000.0));
7984 }
7985 }
7986 }
7987 else
7988 {
7989 if (zcmusic != NULL)
7990 {
7991 zcmusic_stop(zcmusic);
7992 zcmusic_unload_file(zcmusic);
7993 zcmusic = NULL;
7994 zcmixer->newtrack = NULL;
7995 }
7996
7997 zcmusic = zcmusic_load_for_quest(DMaps[currdmap].tmusic, qstpath).first;
7998 zcmixer->newtrack = zcmusic;
7999
8000 if (zcmusic != NULL)
8001 {
8002 zc_stop_midi();
8003 strcpy(tfile, DMaps[currdmap].tmusic);
8004 zcmusic_play(zcmusic, emusic_volume);
8005 int32_t temptracks = 0;
8006 temptracks = zcmusic_get_tracks(zcmusic);
8007 temptracks = (temptracks < 2) ? 1 : temptracks;
8008 ttrack = vbound(DMaps[currdmap].tmusictrack, 0, temptracks - 1);
8009 zcmusic_change_track(zcmusic, ttrack);
8010 zcmusic_set_loop(zcmusic, double(DMaps[currdmap].tmusic_loop_start / 10000.0), double(DMaps[currdmap].tmusic_loop_end / 10000.0));
8011 }
8012 else
8013 {
8014 tfile[0] = 0;
8015 domidi = true;
8016 }
8017 }
8018 }
8019 }
8020 else
8021 {
8022 if (DMaps[currdmap].midi == 0 && fadeoutframes > 0 && zcmusic != NULL && strcmp(zcmusic->filename, DMaps[currdmap].tmusic) != 0)
8023 {
8024 play_enh_music_crossfade(NULL, qstpath, DMaps[currdmap].tmusictrack, get_emusic_volume(), DMaps[currdmap].tmusic_xfade_in, fadeoutframes);
8025 }
8026 else
8027 {
8028 domidi = true;
8029 }
8030 }
8031
8032 if(domidi)
8033 {
8034 int32_t m=DMaps[currdmap].midi;
8035
8036 switch(m)
8037 {
8038 case 1:
8039 jukebox(ZC_MIDI_OVERWORLD);
8040 break;
8041
8042 case 2:
8043 jukebox(ZC_MIDI_DUNGEON);
8044 break;
8045
8046 case 3:
8047 jukebox(ZC_MIDI_LEVEL9);
8048 break;
8049
8050 default:
8051 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8052 jukebox(m+MIDIOFFSET_DMAP);
8053 else
8054 music_stop();
8055 }
8056 }
8057 100 }
8058
8059 34886 void playLevelMusic()
8060 {
8061
1/2
✓ Branch 0 taken 34886 times.
✗ Branch 1 not taken.
34886 if (is_headless())
8062 34886 return;
8063
8064 int32_t m=tmpscr->screen_midi;
8065
8066 switch(m)
8067 {
8068 case -2:
8069 music_stop();
8070 break;
8071
8072 case -1:
8073 play_DmapMusic();
8074 break;
8075
8076 case 1:
8077 jukebox(ZC_MIDI_OVERWORLD);
8078 break;
8079
8080 case 2:
8081 jukebox(ZC_MIDI_DUNGEON);
8082 break;
8083
8084 case 3:
8085 jukebox(ZC_MIDI_LEVEL9);
8086 break;
8087
8088 default:
8089 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8090 jukebox(m+MIDIOFFSET_MAPSCR);
8091 else
8092 music_stop();
8093 }
8094 34886 }
8095
8096 4262 void master_volume(int32_t dv,int32_t mv)
8097 {
8098
7/8
✓ Branch 0 taken 2008 times.
✓ Branch 1 taken 2254 times.
✓ Branch 2 taken 1967 times.
✓ Branch 3 taken 287 times.
✓ Branch 4 taken 2254 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1967 times.
✓ Branch 7 taken 287 times.
4262 if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
8099
8100
7/8
✓ Branch 0 taken 2004 times.
✓ Branch 1 taken 2258 times.
✓ Branch 2 taken 2000 times.
✓ Branch 3 taken 258 times.
✓ Branch 4 taken 2258 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2000 times.
✓ Branch 7 taken 258 times.
4262 if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
8101
8102
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4262 times.
✓ Branch 2 taken 4262 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4262 times.
4262 int32_t i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
8103 4262 int32_t temp_vol = midi_volume;
8104
2/2
✓ Branch 0 taken 4016 times.
✓ Branch 1 taken 246 times.
4262 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
8105 246 temp_vol = (midi_volume * FFCore.usr_music_volume) / 10000 / 100;
8106 4262 zc_set_volume(digi_volume,mixvol(tunes[i].volume, temp_vol));
8107 4262 }
8108
8109 // array of voices, one for each sfx sample in the data file
8110 // 0+ = voice #
8111 // -1 = voice not allocated
8112 246 void Z_init_sound()
8113 {
8114
2/2
✓ Branch 0 taken 62976 times.
✓ Branch 1 taken 246 times.
63222 for(int32_t i=0; i<WAV_COUNT; i++)
8115 62976 sfx_voice[i]=-1;
8116
8117 246 const char* midis[ZC_MIDI_COUNT] = {
8118 "assets/dungeon.mid",
8119 "assets/ending.mid",
8120 "assets/gameover.mid",
8121 "assets/level9.mid",
8122 "assets/overworld.mid",
8123 "assets/title.mid",
8124 "assets/triforce.mid",
8125 };
8126
2/2
✓ Branch 0 taken 1722 times.
✓ Branch 1 taken 246 times.
1968 for(int32_t i=0; i<ZC_MIDI_COUNT; i++)
8127 {
8128 1722 tunes[i].data = load_midi(midis[i]);
8129
1/2
✓ Branch 0 taken 1722 times.
✗ Branch 1 not taken.
1722 if (!tunes[i].data)
8130 Z_error_fatal("Missing required file %s\n", midis[i]);
8131 1722 }
8132
8133
2/2
✓ Branch 0 taken 61992 times.
✓ Branch 1 taken 246 times.
62238 for(int32_t j=0; j<MAXCUSTOMMIDIS; j++)
8134 61992 tunes[ZC_MIDI_COUNT+j].data=NULL;
8135
8136 246 master_volume(digi_volume,midi_volume);
8137 246 }
8138
8139 // returns number of voices currently allocated
8140 int32_t sfx_count()
8141 {
8142 int32_t c=0;
8143
8144 for(int32_t i=0; i<WAV_COUNT; i++)
8145 if(sfx_voice[i]!=-1)
8146 ++c;
8147
8148 return c;
8149 }
8150
8151 // clean up finished samples
8152 18109735 void sfx_cleanup()
8153 {
8154
2/2
✓ Branch 0 taken 4636092160 times.
✓ Branch 1 taken 18109735 times.
4654201895 for(int32_t i=0; i<WAV_COUNT; i++)
8155
3/4
✓ Branch 0 taken 1257775 times.
✓ Branch 1 taken 4634834385 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1257775 times.
4637349935 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
8156 {
8157 1257775 deallocate_voice(sfx_voice[i]);
8158 1257775 sfx_voice[i]=-1;
8159 1257775 }
8160 18109735 }
8161
8162 1257912 SAMPLE* sfx_get_sample(int32_t index)
8163 {
8164 // check index
8165
2/4
✓ Branch 0 taken 1257912 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1257912 times.
1257912 if (index<=0 || index>=WAV_COUNT)
8166 return nullptr;
8167
8168
2/2
✓ Branch 0 taken 446247 times.
✓ Branch 1 taken 811665 times.
1257912 if (sfxdat)
8169 {
8170
1/2
✓ Branch 0 taken 446247 times.
✗ Branch 1 not taken.
446247 if (index<Z35)
8171 {
8172 446247 return (SAMPLE*)sfxdata[index].dat;
8173 }
8174 else
8175 {
8176 return (SAMPLE*)sfxdata[Z35].dat;
8177 }
8178 }
8179 else
8180 {
8181 811665 return &customsfxdata[index];
8182 }
8183
8184 return nullptr;
8185 1257912 }
8186
8187 // allocates a voice for the sample "wav_index" (index into zelda.dat)
8188 // if a voice is already allocated (and/or playing), then it just returns true
8189 // Returns true: voice is allocated
8190 // false: unsuccessful
8191 1848912 bool sfx_init(int32_t index)
8192 {
8193 // check index
8194
3/4
✓ Branch 0 taken 1388740 times.
✓ Branch 1 taken 460172 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1388740 times.
1848912 if(index<=0 || index>=WAV_COUNT)
8195 460172 return false;
8196
8197
2/2
✓ Branch 0 taken 130874 times.
✓ Branch 1 taken 1257866 times.
1388740 if (sfx_voice[index] == -1)
8198 {
8199 1257866 SAMPLE* sample = sfx_get_sample(index);
8200
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1257866 times.
1257866 if (!sample)
8201 return false;
8202
8203 1257866 sfx_voice[index] = allocate_voice(sample);
8204 1257866 }
8205
8206 1388740 return sfx_voice[index] != -1;
8207 1848912 }
8208
8209 int32_t sfx_get_default_freq(int32_t index)
8210 {
8211 if (sfxdat)
8212 {
8213 if (index < Z35)
8214 {
8215 return ((SAMPLE*)sfxdata[index].dat)->freq;
8216 }
8217 else
8218 {
8219 return ((SAMPLE*)sfxdata[Z35].dat)->freq;
8220 }
8221 }
8222 else
8223 {
8224 return customsfxdata[index].freq;
8225 }
8226 }
8227
8228 int32_t sfx_get_length(int32_t index)
8229 {
8230 if (sfxdat)
8231 {
8232 if (index < Z35)
8233 {
8234 return int32_t(((SAMPLE*)sfxdata[index].dat)->len);
8235 }
8236 else
8237 {
8238 return int32_t(((SAMPLE*)sfxdata[Z35].dat)->len);
8239 }
8240 }
8241 else
8242 {
8243 return int32_t(customsfxdata[index].len);
8244 }
8245 }
8246
8247 // plays an sfx sample
8248 1848912 void sfx(int32_t index,int32_t pan,bool loop, bool restart, int32_t vol, int32_t freq)
8249 {
8250
2/2
✓ Branch 0 taken 1388740 times.
✓ Branch 1 taken 460172 times.
1848912 if(!sfx_init(index))
8251 460172 return;
8252
1/2
✓ Branch 0 taken 1388740 times.
✗ Branch 1 not taken.
1388740 if (!is_headless())
8253 {
8254 voice_set_playmode(sfx_voice[index], loop ? PLAYMODE_LOOP : PLAYMODE_PLAY);
8255 voice_set_pan(sfx_voice[index], pan);
8256
8257 // Only used by ZScript currently
8258 if (freq <= -1)
8259 {
8260 freq = sfx_get_default_freq(index);
8261 }
8262 voice_set_frequency(sfx_voice[index], freq);
8263
8264 // Only used by ZScript currently
8265 int32_t temp_volume = (sfx_volume * vol) / 10000 / 100;
8266 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8267 temp_volume = (temp_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8268 voice_set_volume(sfx_voice[index], temp_volume);
8269
8270 int32_t pos = voice_get_position(sfx_voice[index]);
8271
8272 if (restart) voice_set_position(sfx_voice[index], 0);
8273
8274 if (pos <= 0)
8275 voice_start(sfx_voice[index]);
8276 }
8277
8278
4/4
✓ Branch 0 taken 857521 times.
✓ Branch 1 taken 531219 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 857513 times.
1388740 if (restart && replay_is_debug())
8279 {
8280 // TODO: get rid of this bandaid next time replays are mass-updated.
8281 857513 const char* sfx_name = sfx_string[index];
8282
2/2
✓ Branch 0 taken 845806 times.
✓ Branch 1 taken 11707 times.
857513 if (strcmp(sfx_name, "Hero is hit") == 0)
8283 11707 sfx_name = "Player is hit";
8284
2/2
✓ Branch 0 taken 845684 times.
✓ Branch 1 taken 122 times.
845806 else if (strcmp(sfx_name, "Hero dies") == 0)
8285 122 sfx_name = "Player dies";
8286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 857513 times.
857513 replay_step_comment(fmt::format("sfx {}", sfx_name));
8287 857513 }
8288 1848912 }
8289
8290 // true if sfx is allocated
8291 198761 bool sfx_allocated(int32_t index)
8292 {
8293
3/4
✓ Branch 0 taken 33450 times.
✓ Branch 1 taken 165311 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33450 times.
198761 return (index>0 && index<WAV_COUNT && sfx_voice[index]!=-1);
8294 }
8295
8296 // start it (in loop mode) if it's not already playing,
8297 // otherwise adjust it to play in loop mode -DD
8298 117025 void cont_sfx(int32_t index)
8299 {
8300
1/2
✓ Branch 0 taken 117025 times.
✗ Branch 1 not taken.
117025 if (is_headless())
8301 117025 return;
8302
8303 if(!sfx_init(index))
8304 {
8305 return;
8306 }
8307
8308 if(voice_get_position(sfx_voice[index])<=0)
8309 {
8310 voice_set_position(sfx_voice[index],0);
8311 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
8312 voice_set_volume(sfx_voice[index], sfx_volume);
8313 voice_start(sfx_voice[index]);
8314 }
8315 else
8316 {
8317 adjust_sfx(index, 128, true);
8318 }
8319 117025 }
8320
8321 // adjust parameters while playing
8322 4903 void adjust_sfx(int32_t index,int32_t pan,bool loop)
8323 {
8324
4/6
✓ Branch 0 taken 4467 times.
✓ Branch 1 taken 436 times.
✓ Branch 2 taken 4467 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4467 times.
4903 if(index<=0 || index>=WAV_COUNT || sfx_voice[index]==-1)
8325 4903 return;
8326
8327 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
8328 voice_set_pan(sfx_voice[index],pan);
8329 4903 }
8330
8331 // pauses a voice
8332 3223 void pause_sfx(int32_t index)
8333 {
8334
3/6
✓ Branch 0 taken 3223 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3223 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3223 times.
3223 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8335 voice_stop(sfx_voice[index]);
8336 3223 }
8337
8338 // resumes a voice
8339 1360 void resume_sfx(int32_t index)
8340 {
8341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1360 times.
1360 if (is_headless())
8342 1360 return;
8343
8344 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8345 voice_start(sfx_voice[index]);
8346 1360 }
8347
8348 // pauses all active voices
8349 1072 void pause_all_sfx()
8350 {
8351
2/2
✓ Branch 0 taken 274432 times.
✓ Branch 1 taken 1072 times.
275504 for(int32_t i=0; i<WAV_COUNT; i++)
8352
2/2
✓ Branch 0 taken 274430 times.
✓ Branch 1 taken 2 times.
274434 if(sfx_voice[i]!=-1)
8353 2 voice_stop(sfx_voice[i]);
8354 1072 }
8355
8356 // resumes all paused voices
8357 1017 void resume_all_sfx()
8358 {
8359
2/2
✓ Branch 0 taken 260352 times.
✓ Branch 1 taken 1017 times.
261369 for(int32_t i=0; i<WAV_COUNT; i++)
8360
1/2
✓ Branch 0 taken 260352 times.
✗ Branch 1 not taken.
260352 if(sfx_voice[i]!=-1)
8361 voice_start(sfx_voice[i]);
8362 1017 }
8363
8364 // stops an sfx and deallocates the voice
8365 14464641 void stop_sfx(int32_t index)
8366 {
8367
3/4
✓ Branch 0 taken 14218318 times.
✓ Branch 1 taken 246323 times.
✓ Branch 2 taken 14218318 times.
✗ Branch 3 not taken.
14464641 if(index<=0 || index>=WAV_COUNT)
8368 246323 return;
8369
8370
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 14218285 times.
14218318 if(sfx_voice[index]!=-1)
8371 {
8372 33 deallocate_voice(sfx_voice[index]);
8373 33 sfx_voice[index]=-1;
8374 33 }
8375 14464641 }
8376
8377 // Stops SFX played by Hero's item of the given family
8378 129758 void stop_item_sfx(int32_t family)
8379 {
8380 129758 int32_t id=current_item_id(family);
8381
8382
2/2
✓ Branch 0 taken 128658 times.
✓ Branch 1 taken 1100 times.
129758 if(id<0)
8383 128658 return;
8384
8385 1100 stop_sfx(itemsbuf[id].usesound);
8386 129758 }
8387
8388 9165 void kill_sfx()
8389 {
8390
2/2
✓ Branch 0 taken 2346240 times.
✓ Branch 1 taken 9165 times.
2355405 for(int32_t i=0; i<WAV_COUNT; i++)
8391
2/2
✓ Branch 0 taken 2346182 times.
✓ Branch 1 taken 58 times.
2346298 if(sfx_voice[i]!=-1)
8392 {
8393 58 deallocate_voice(sfx_voice[i]);
8394 58 sfx_voice[i]=-1;
8395 58 }
8396 9165 }
8397
8398 1172880 int32_t pan(int32_t x)
8399 {
8400
1/4
✓ Branch 0 taken 1172880 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1172880 switch(pan_style)
8401 {
8402 case 0:
8403 return 128;
8404
8405 case 1:
8406 1172880 return vbound((x>>1)+68,0,255);
8407
8408 case 2:
8409 return vbound(((x*3)>>2)+36,0,255);
8410 }
8411
8412 return vbound(x,0,255);
8413 1172880 }
8414
8415 49898820 bool joybtn(int32_t b)
8416 {
8417
1/2
✓ Branch 0 taken 49898820 times.
✗ Branch 1 not taken.
49898820 if(b == 0)
8418 return false;
8419
1/2
✓ Branch 0 taken 49898820 times.
✗ Branch 1 not taken.
49898820 if (b-1 >= joy[joystick_index].num_buttons)
8420 49898820 return false;
8421
8422 return joy[joystick_index].button[b-1].b !=0;
8423 49898820 }
8424
8425 bool joystick(int32_t s)
8426 {
8427 if(s < 0)
8428 return false;
8429 if (s >= joy[joystick_index].num_sticks)
8430 return false;
8431
8432 for (int i = 0; i < joy[joystick_index].stick[s].num_axis; i++)
8433 {
8434 if (joy[joystick_index].stick[s].axis[i].d1 || joy[joystick_index].stick[s].axis[i].d2)
8435 return true;
8436 }
8437 return false;
8438 }
8439
8440 const char* joybtn_name(int32_t b)
8441 {
8442 if (b <= 0 || b > joy[joystick_index].num_buttons)
8443 return "";
8444
8445 return joy[joystick_index].button[b-1].name;
8446 }
8447
8448 const char* joystick_name(int32_t s)
8449 {
8450 if (s < 0 || s >= joy[joystick_index].num_sticks)
8451 return "";
8452
8453 return joy[joystick_index].stick[s].name;
8454 }
8455
8456 int32_t button_pressed()
8457 {
8458 if (joystick_index >= MAX_JOYSTICKS)
8459 return 0;
8460
8461 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8462 {
8463 if(joybtn(i))
8464 return i;
8465 }
8466
8467 return 0;
8468 }
8469
8470 int32_t next_press_key();
8471
8472 int32_t next_joy_input(bool buttons)
8473 {
8474 clear_keybuf();
8475
8476 //first, we need to wait until they're pressing no buttons
8477 for(;;)
8478 {
8479 if(keypressed())
8480 {
8481 switch(readkey()>>8)
8482 {
8483 case KEY_ESC:
8484 return -1;
8485
8486 case KEY_SPACE:
8487 return 0;
8488 }
8489 }
8490
8491 poll_joystick();
8492 bool done = true;
8493
8494 if (buttons)
8495 {
8496 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8497 {
8498 if(joybtn(i)) done = false;
8499 }
8500 }
8501 else
8502 {
8503 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8504 {
8505 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8506 return -2;
8507 }
8508 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8509 {
8510 if(joystick(i)) done = false;
8511 }
8512 }
8513
8514 if(done) break;
8515 rest(1);
8516 }
8517
8518 //now, we need to wait for them to press any button
8519 for(;;)
8520 {
8521 if(keypressed())
8522 {
8523 switch(readkey()>>8)
8524 {
8525 case KEY_ESC:
8526 return -1;
8527
8528 case KEY_SPACE:
8529 return 0;
8530 }
8531 }
8532
8533 poll_joystick();
8534
8535 if (buttons)
8536 {
8537 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8538 {
8539 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8540 return -2;
8541 }
8542 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8543 {
8544 if(joybtn(i))
8545 return i;
8546 }
8547 }
8548 else
8549 {
8550 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8551 {
8552 if(joystick(i))
8553 return i;
8554 }
8555 }
8556 rest(1);
8557 }
8558 }
8559
8560 7240529 static bool rButton(bool &btn, bool &flag, bool rawbtn)
8561 {
8562
2/2
✓ Branch 0 taken 7214975 times.
✓ Branch 1 taken 25554 times.
7240529 bool ret = btn && !flag;
8563 7240529 flag = rawbtn;
8564
8565 7240529 return ret;
8566 }
8567 373615728 static bool rButton(bool &btn, bool &flag)
8568 {
8569
2/2
✓ Branch 0 taken 359853440 times.
✓ Branch 1 taken 13762288 times.
373615728 bool ret = btn && !flag;
8570 373615728 flag = btn;
8571
8572 373615728 return ret;
8573 }
8574 4574878 static bool rButtonPeek(bool btn, bool flag)
8575 {
8576
2/2
✓ Branch 0 taken 4234696 times.
✓ Branch 1 taken 340182 times.
4574878 if(!btn)
8577 {
8578 4234696 return false;
8579 }
8580
2/2
✓ Branch 0 taken 33303 times.
✓ Branch 1 taken 306879 times.
340182 else if(!flag)
8581 {
8582 33303 return true;
8583 }
8584
8585 306879 return false;
8586 4574878 }
8587
8588 // Updated only by keyboard/gamepad.
8589 // If in replay mode, this is set directly by the replay system.
8590 // This should never be read from directly - use control_state instead.
8591 bool raw_control_state[ZC_CONTROL_STATES];
8592
8593 // Every call to load_control_state (pretty much every frame) resets this to be equal to raw_control_state.
8594 // This state can drift from raw_control_state if button states are "eaten" or overriden by a script. But that only
8595 // lasts until the next call to load_control_state.
8596 bool control_state[ZC_CONTROL_STATES];
8597 bool disable_control[ZC_CONTROL_STATES];
8598 bool drunk_toggle_state[11];
8599 bool disabledKeys[127];
8600 bool KeyInput[127];
8601 bool KeyPress[127];
8602
8603 bool key_current_frame[127];
8604 bool key_previous_frame[127];
8605
8606 static bool key_system[127];
8607 static bool key_system_previous[127];
8608 static bool key_system_press[127];
8609
8610 bool button_press[ZC_CONTROL_STATES];
8611 bool button_hold[ZC_CONTROL_STATES];
8612
8613 #define STICK_1_X joy[joystick_index].stick[js_stick_1_x_stick].axis[js_stick_1_x_axis]
8614 #define STICK_1_Y joy[joystick_index].stick[js_stick_1_y_stick].axis[js_stick_1_y_axis]
8615 #define STICK_2_X joy[joystick_index].stick[js_stick_2_x_stick].axis[js_stick_2_x_axis]
8616 #define STICK_2_Y joy[joystick_index].stick[js_stick_2_y_stick].axis[js_stick_2_y_axis]
8617 #define STICK_PRECISION 56 //define your own sensitivity
8618
8619 15505307 void load_control_state()
8620 {
8621 15505307 load_control_called_this_frame = true;
8622
8623
2/2
✓ Branch 0 taken 12375675 times.
✓ Branch 1 taken 3129632 times.
15505307 if (replay_version_check(8, 11))
8624 {
8625
2/2
✓ Branch 0 taken 56333376 times.
✓ Branch 1 taken 3129632 times.
59463008 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8626 56333376 down_control_states[i] = raw_control_state[i];
8627 3129632 }
8628
8629
2/2
✓ Branch 0 taken 15505286 times.
✓ Branch 1 taken 21 times.
15505307 if (!replay_is_replaying())
8630 {
8631
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[0]=zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset < -STICK_PRECISION : joybtn(DUbtn));
8632
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[1]=zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn));
8633
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[2]=zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn));
8634
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[3]=zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn));
8635
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[4]=zc_getrawkey(Akey, true)||joybtn(Abtn);
8636
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[5]=zc_getrawkey(Bkey, true)||joybtn(Bbtn);
8637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[6]=zc_getrawkey(Skey, true)||joybtn(Sbtn);
8638
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[7]=zc_getrawkey(Lkey, true)||joybtn(Lbtn);
8639
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[8]=zc_getrawkey(Rkey, true)||joybtn(Rbtn);
8640
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[9]=zc_getrawkey(Pkey, true)||joybtn(Pbtn);
8641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[10]=zc_getrawkey(Exkey1, true)||joybtn(Exbtn1);
8642
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[11]=zc_getrawkey(Exkey2, true)||joybtn(Exbtn2);
8643
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[12]=zc_getrawkey(Exkey3, true)||joybtn(Exbtn3);
8644
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[13]=zc_getrawkey(Exkey4, true)||joybtn(Exbtn4);
8645
8646
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if(num_joysticks != 0)
8647 {
8648 raw_control_state[14] = STICK_2_Y.pos - js_stick_2_y_offset < -STICK_PRECISION;
8649 raw_control_state[15] = STICK_2_Y.pos - js_stick_2_y_offset > STICK_PRECISION;
8650 raw_control_state[16] = STICK_2_X.pos - js_stick_2_x_offset < -STICK_PRECISION;
8651 raw_control_state[17] = STICK_2_X.pos - js_stick_2_x_offset > STICK_PRECISION;
8652 }
8653 else
8654 {
8655 21 raw_control_state[14] = false;
8656 21 raw_control_state[15] = false;
8657 21 raw_control_state[16] = false;
8658 21 raw_control_state[17] = false;
8659 }
8660 21 }
8661
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 15505302 times.
15505307 if (replay_is_active())
8662 {
8663
2/2
✓ Branch 0 taken 1211700 times.
✓ Branch 1 taken 14293602 times.
15505302 if (replay_get_version() < 3)
8664 1211700 replay_poll();
8665
4/4
✓ Branch 0 taken 14293581 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 12532206 times.
✓ Branch 3 taken 1761375 times.
14293602 else if (replay_is_replaying() && replay_get_version() < 6)
8666 1761375 replay_peek_input();
8667
4/4
✓ Branch 0 taken 12532206 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 9402574 times.
✓ Branch 3 taken 3129632 times.
12532227 else if (replay_is_replaying() && replay_version_check(8, 11))
8668 3129632 replay_peek_input();
8669
2/2
✓ Branch 0 taken 14238790 times.
✓ Branch 1 taken 1266512 times.
15505302 if (replay_get_version() == 8)
8670 1266512 update_keys();
8671 15505302 }
8672
8673 // Some test replay files were made before a serious input bug was fixed, so instead
8674 // of re-doing them or tossing them out, just check for that zplay version.
8675
3/4
✓ Branch 0 taken 15505297 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121900 times.
✓ Branch 3 taken 15383397 times.
15505307 bool botched_input = replay_is_active() && replay_get_version() != 1 && replay_get_version() < 8;
8676
2/2
✓ Branch 0 taken 279095346 times.
✓ Branch 1 taken 15505297 times.
294600643 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8677 {
8678 279095346 control_state[i] = raw_control_state[i];
8679
4/4
✓ Branch 0 taken 53024022 times.
✓ Branch 1 taken 226071324 times.
✓ Branch 2 taken 2611994 times.
✓ Branch 3 taken 50412028 times.
279095346 if (botched_input && !control_state[i])
8680 50412028 down_control_states[i] = false;
8681 279095346 }
8682 15505297 bool did_bad_cutscene_btn = false;
8683
2/2
✓ Branch 0 taken 15505297 times.
✓ Branch 1 taken 279095346 times.
294600643 for(int q = 0; q < 18; ++q)
8684
4/4
✓ Branch 0 taken 13193425 times.
✓ Branch 1 taken 265901921 times.
✓ Branch 2 taken 13191842 times.
✓ Branch 3 taken 1583 times.
279096929 if(control_state[q] && !active_cutscene.can_button(q))
8685 {
8686 1583 control_state[q] = false;
8687 1583 did_bad_cutscene_btn = true;
8688 1583 }
8689
2/2
✓ Branch 0 taken 15504152 times.
✓ Branch 1 taken 1145 times.
15505297 if(did_bad_cutscene_btn)
8690 1145 active_cutscene.error();
8691
8692 15505297 button_press[0]=rButton(control_state[0],button_hold[0]);
8693 15505297 button_press[1]=rButton(control_state[1],button_hold[1]);
8694 15505297 button_press[2]=rButton(control_state[2],button_hold[2]);
8695 15505297 button_press[3]=rButton(control_state[3],button_hold[3]);
8696 15505297 button_press[4]=rButton(control_state[4],button_hold[4]);
8697 15505297 button_press[5]=rButton(control_state[5],button_hold[5]);
8698 15505297 button_press[6]=rButton(control_state[6],button_hold[6]);
8699 15505297 button_press[7]=rButton(control_state[7],button_hold[7]);
8700 15505297 button_press[8]=rButton(control_state[8],button_hold[8]);
8701 15505297 button_press[9]=rButton(control_state[9],button_hold[9]);
8702 15505297 button_press[10]=rButton(control_state[10],button_hold[10]);
8703 15505297 button_press[11]=rButton(control_state[11],button_hold[11]);
8704 15505297 button_press[12]=rButton(control_state[12],button_hold[12]);
8705 15505297 button_press[13]=rButton(control_state[13],button_hold[13]);
8706 15505297 button_press[14]=rButton(control_state[14],button_hold[14]);
8707 15505297 button_press[15]=rButton(control_state[15],button_hold[15]);
8708 15505297 button_press[16]=rButton(control_state[16],button_hold[16]);
8709 15505297 button_press[17]=rButton(control_state[17],button_hold[17]);
8710 15505297 }
8711
8712 // Returns true if any game key is pressed. This is needed because keypressed()
8713 // doesn't detect modifier keys and control_state[] can be modified by scripts.
8714 77849705 bool zc_key_pressed()
8715 //may also need to use zc_getrawkey
8716 {
8717
7/10
✓ Branch 0 taken 62873451 times.
✓ Branch 1 taken 14976254 times.
✓ Branch 2 taken 14976254 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14976254 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12263296 times.
✓ Branch 7 taken 12263296 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4911060 times.
82760765 if((zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset< -STICK_PRECISION : joybtn(DUbtn))) ||
8718
4/6
✓ Branch 0 taken 12263296 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12263296 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9338646 times.
✓ Branch 5 taken 9338646 times.
12263296 (zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn))) ||
8719
4/6
✓ Branch 0 taken 9338646 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9338646 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6191216 times.
✓ Branch 5 taken 6191216 times.
9338646 (zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn))) ||
8720
4/6
✓ Branch 0 taken 6191216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6191216 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5314612 times.
✓ Branch 5 taken 5314612 times.
6191216 (zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn))) ||
8721
1/2
✓ Branch 0 taken 5314612 times.
✗ Branch 1 not taken.
5314612 (zc_getrawkey(Akey, true)||joybtn(Abtn)) ||
8722
3/4
✓ Branch 0 taken 5128945 times.
✓ Branch 1 taken 185667 times.
✓ Branch 2 taken 5128945 times.
✗ Branch 3 not taken.
5314612 (zc_getrawkey(Bkey, true)||joybtn(Bbtn)) ||
8723
3/4
✓ Branch 0 taken 4982840 times.
✓ Branch 1 taken 146105 times.
✓ Branch 2 taken 4982840 times.
✗ Branch 3 not taken.
5128945 (zc_getrawkey(Skey, true)||joybtn(Sbtn)) ||
8724
3/4
✓ Branch 0 taken 4961970 times.
✓ Branch 1 taken 20870 times.
✓ Branch 2 taken 4961970 times.
✗ Branch 3 not taken.
4982840 (zc_getrawkey(Lkey, true)||joybtn(Lbtn)) ||
8725
3/4
✓ Branch 0 taken 4935611 times.
✓ Branch 1 taken 26359 times.
✓ Branch 2 taken 4935611 times.
✗ Branch 3 not taken.
4961970 (zc_getrawkey(Rkey, true)||joybtn(Rbtn)) ||
8726
3/4
✓ Branch 0 taken 4928326 times.
✓ Branch 1 taken 7285 times.
✓ Branch 2 taken 4928326 times.
✗ Branch 3 not taken.
4935611 (zc_getrawkey(Pkey, true)||joybtn(Pbtn)) ||
8727
3/4
✓ Branch 0 taken 4912973 times.
✓ Branch 1 taken 15353 times.
✓ Branch 2 taken 4912973 times.
✗ Branch 3 not taken.
4928326 (zc_getrawkey(Exkey1, true)||joybtn(Exbtn1)) ||
8728
3/4
✓ Branch 0 taken 4911154 times.
✓ Branch 1 taken 1819 times.
✓ Branch 2 taken 4911154 times.
✗ Branch 3 not taken.
4912973 (zc_getrawkey(Exkey2, true)||joybtn(Exbtn2)) ||
8729
3/4
✓ Branch 0 taken 4911119 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 4911119 times.
✗ Branch 3 not taken.
4911154 (zc_getrawkey(Exkey3, true)||joybtn(Exbtn3)) ||
8730
2/2
✓ Branch 0 taken 4911060 times.
✓ Branch 1 taken 59 times.
4911119 (zc_getrawkey(Exkey4, true)||joybtn(Exbtn4))) // Skipping joystick axes
8731 139154185 return true;
8732
8733 4911060 return false;
8734 18318343 }
8735
8736 294634601 bool getInput(int32_t btn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8737 {
8738 294634601 bool ret = false, drunkstate = false, rawret = false;;
8739 294634601 bool* flag = &down_control_states[btn];
8740
2/7
✓ Branch 0 taken 276297455 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 18337146 times.
294634601 switch(btn)
8741 {
8742 case btnF12:
8743 ret = zc_getkey(KEY_F12, ignoreDisable);
8744 rawret = zc_getrawkey(KEY_F12, ignoreDisable);
8745 eatEntirely = false;
8746 break;
8747 case btnF11:
8748 ret = zc_getkey(KEY_F11, ignoreDisable);
8749 rawret = zc_getrawkey(KEY_F11, ignoreDisable);
8750 eatEntirely = false;
8751 break;
8752 case btnF5:
8753 ret = zc_getkey(KEY_F5, ignoreDisable);
8754 rawret = zc_getrawkey(KEY_F5, ignoreDisable);
8755 eatEntirely = false;
8756 break;
8757 case btnQ:
8758 ret = zc_getkey(KEY_Q, ignoreDisable);
8759 rawret = zc_getrawkey(KEY_Q, ignoreDisable);
8760 eatEntirely = false;
8761 break;
8762 case btnI:
8763 ret = zc_getkey(KEY_I, ignoreDisable);
8764 rawret = zc_getrawkey(KEY_I, ignoreDisable);
8765 eatEntirely = false;
8766 break;
8767 case btnM:
8768
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18337146 times.
18337146 if(FFCore.kb_typing_mode) return false;
8769 18337146 rawret = ret = zc_getrawkey(KEY_ESC, ignoreDisable);
8770 18337146 eatEntirely = false;
8771 18337146 break;
8772 default: //control_state[] index
8773
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 276297455 times.
276297455 if(FFCore.kb_typing_mode) return false;
8774
6/6
✓ Branch 0 taken 274919447 times.
✓ Branch 1 taken 1378008 times.
✓ Branch 2 taken 16536341 times.
✓ Branch 3 taken 258383106 times.
✓ Branch 4 taken 16536188 times.
✓ Branch 5 taken 153 times.
276297455 if(!ignoreDisable && get_qr(qr_FIXDRUNKINPUTS) && disable_control[btn]) drunk = false;
8775
2/2
✓ Branch 0 taken 15728053 times.
✓ Branch 1 taken 260569249 times.
276297302 else if(btn<11) drunkstate = drunk_toggle_state[btn];
8776
4/4
✓ Branch 0 taken 245520317 times.
✓ Branch 1 taken 30777138 times.
✓ Branch 2 taken 7155 times.
✓ Branch 3 taken 30769983 times.
307074593 ret = control_state[btn] && (ignoreDisable || !disable_control[btn]);
8777 276297455 rawret = raw_control_state[btn];
8778 276297455 }
8779
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 294634601 times.
294634601 assert(flag);
8780
2/2
✓ Branch 0 taken 188298812 times.
✓ Branch 1 taken 106335789 times.
294634601 if(press)
8781 {
8782
2/2
✓ Branch 0 taken 4574878 times.
✓ Branch 1 taken 101760911 times.
106335789 if(peek)
8783 4574878 ret = rButtonPeek(ret, *flag);
8784
2/2
✓ Branch 0 taken 94520382 times.
✓ Branch 1 taken 7240529 times.
101760911 else if(get_qr(qr_BROKEN_INPUT_DOWN_STATE)) ret = rButton(ret, *flag);
8785 7240529 else ret = rButton(ret, *flag, rawret);
8786 106335789 }
8787
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 294634601 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
294634601 if(eatEntirely && ret) control_state[btn] = false;
8788
4/4
✓ Branch 0 taken 220128723 times.
✓ Branch 1 taken 74505878 times.
✓ Branch 2 taken 220128642 times.
✓ Branch 3 taken 81 times.
294634601 if(drunk && drunkstate) ret = !ret;
8789 294634601 return ret;
8790 294634601 }
8791
8792 14795919 byte getIntBtnInput(byte intbtn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8793 {
8794 14795919 byte ret = 0;
8795
2/2
✓ Branch 0 taken 10444473 times.
✓ Branch 1 taken 4351446 times.
14795919 if(intbtn & INT_BTN_A) ret |= getInput(btnA, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_A : 0;
8796
2/2
✓ Branch 0 taken 14588690 times.
✓ Branch 1 taken 207229 times.
14795919 if(intbtn & INT_BTN_B) ret |= getInput(btnB, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_B : 0;
8797
2/2
✓ Branch 0 taken 14589137 times.
✓ Branch 1 taken 206782 times.
14795919 if(intbtn & INT_BTN_L) ret |= getInput(btnL, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_L : 0;
8798
2/2
✓ Branch 0 taken 14589137 times.
✓ Branch 1 taken 206782 times.
14795919 if(intbtn & INT_BTN_R) ret |= getInput(btnR, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_R : 0;
8799
2/2
✓ Branch 0 taken 14589137 times.
✓ Branch 1 taken 206782 times.
14795919 if(intbtn & INT_BTN_EX1) ret |= getInput(btnEx1, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX1 : 0;
8800
2/2
✓ Branch 0 taken 14589137 times.
✓ Branch 1 taken 206782 times.
14795919 if(intbtn & INT_BTN_EX2) ret |= getInput(btnEx2, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX2 : 0;
8801
2/2
✓ Branch 0 taken 14589137 times.
✓ Branch 1 taken 206782 times.
14795919 if(intbtn & INT_BTN_EX3) ret |= getInput(btnEx3, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX3 : 0;
8802
2/2
✓ Branch 0 taken 14589022 times.
✓ Branch 1 taken 206897 times.
14795919 if(intbtn & INT_BTN_EX4) ret |= getInput(btnEx4, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX4 : 0;
8803 14795919 return ret; //No early return, to make sure all button presses are eaten that should be! -Em
8804 }
8805
8806 7010 byte checkIntBtnVal(byte intbtn, byte vals)
8807 {
8808 7010 return intbtn&vals;
8809 }
8810
8811 3710445 bool Up()
8812 {
8813 3710445 return getInput(btnUp);
8814 }
8815 726817 bool Down()
8816 {
8817 726817 return getInput(btnDown);
8818 }
8819 979837 bool Left()
8820 {
8821 979837 return getInput(btnLeft);
8822 }
8823 1040595 bool Right()
8824 {
8825 1040595 return getInput(btnRight);
8826 }
8827 537139 bool cAbtn()
8828 {
8829 537139 return getInput(btnA);
8830 }
8831 3312971 bool cBbtn()
8832 {
8833 3312971 return getInput(btnB);
8834 }
8835 bool cSbtn()
8836 {
8837 return getInput(btnS);
8838 }
8839 208608 bool cLbtn()
8840 {
8841 208608 return getInput(btnL);
8842 }
8843 208608 bool cRbtn()
8844 {
8845 208608 return getInput(btnR);
8846 }
8847 bool cPbtn()
8848 {
8849 return getInput(btnP);
8850 }
8851 bool cEx1btn()
8852 {
8853 return getInput(btnEx1);
8854 }
8855 bool cEx2btn()
8856 {
8857 return getInput(btnEx2);
8858 }
8859 bool cEx3btn()
8860 {
8861 return getInput(btnEx3);
8862 }
8863 bool cEx4btn()
8864 {
8865 return getInput(btnEx4);
8866 }
8867 bool AxisUp()
8868 {
8869 return getInput(btnAxisUp);
8870 }
8871 bool AxisDown()
8872 {
8873 return getInput(btnAxisDown);
8874 }
8875 bool AxisLeft()
8876 {
8877 return getInput(btnAxisLeft);
8878 }
8879 bool AxisRight()
8880 {
8881 return getInput(btnAxisRight);
8882 }
8883
8884 bool cMbtn()
8885 {
8886 return getInput(btnM);
8887 }
8888 bool cF12()
8889 {
8890 return getInput(btnF12);
8891 }
8892 bool cF11()
8893 {
8894 return getInput(btnF11);
8895 }
8896 bool cF5()
8897 {
8898 return getInput(btnF5);
8899 }
8900 bool cQ()
8901 {
8902 return getInput(btnQ);
8903 }
8904 bool cI()
8905 {
8906 return getInput(btnI);
8907 }
8908
8909 208304 bool rUp()
8910 {
8911 208304 return getInput(btnUp, true);
8912 }
8913 208096 bool rDown()
8914 {
8915 208096 return getInput(btnDown, true);
8916 }
8917 207900 bool rLeft()
8918 {
8919 207900 return getInput(btnLeft, true);
8920 }
8921 207171 bool rRight()
8922 {
8923 207171 return getInput(btnRight, true);
8924 }
8925 6589 bool rAbtn()
8926 {
8927 6589 return getInput(btnA, true);
8928 }
8929 4638 bool rBbtn()
8930 {
8931 4638 return getInput(btnB, true);
8932 }
8933 14366917 bool rSbtn()
8934 {
8935 14366917 return getInput(btnS, true);
8936 }
8937 18318343 bool rMbtn()
8938 {
8939 18318343 return getInput(btnM, true);
8940 }
8941 185250 bool rLbtn()
8942 {
8943 185250 return getInput(btnL, true);
8944 }
8945 185245 bool rRbtn()
8946 {
8947 185245 return getInput(btnR, true);
8948 }
8949 14367651 bool rPbtn()
8950 {
8951 14367651 return getInput(btnP, true);
8952 }
8953 bool rEx1btn()
8954 {
8955 return getInput(btnEx1, true);
8956 }
8957 bool rEx2btn()
8958 {
8959 return getInput(btnEx2, true);
8960 }
8961 195896 bool rEx3btn()
8962 {
8963 195896 return getInput(btnEx3, true);
8964 }
8965 195896 bool rEx4btn()
8966 {
8967 195896 return getInput(btnEx4, true);
8968 }
8969 bool rAxisUp()
8970 {
8971 return getInput(btnAxisUp, true);
8972 }
8973 bool rAxisDown()
8974 {
8975 return getInput(btnAxisDown, true);
8976 }
8977 bool rAxisLeft()
8978 {
8979 return getInput(btnAxisLeft, true);
8980 }
8981 bool rAxisRight()
8982 {
8983 return getInput(btnAxisRight, true);
8984 }
8985
8986 bool rF11()
8987 {
8988 return getInput(btnF11, true);
8989 }
8990 bool rQ()
8991 {
8992 return getInput(btnQ, true);
8993 }
8994 bool rI()
8995 {
8996 return getInput(btnI, true);
8997 }
8998
8999 36581418 bool DrunkUp()
9000 {
9001 36581418 return getInput(btnUp, false, true);
9002 }
9003 33382974 bool DrunkDown()
9004 {
9005 33382974 return getInput(btnDown, false, true);
9006 }
9007 19578341 bool DrunkLeft()
9008 {
9009 19578341 return getInput(btnLeft, false, true);
9010 }
9011 16658670 bool DrunkRight()
9012 {
9013 16658670 return getInput(btnRight, false, true);
9014 }
9015 15772123 bool DrunkcAbtn()
9016 {
9017 15772123 return getInput(btnA, false, true);
9018 }
9019 15208529 bool DrunkcBbtn()
9020 {
9021 15208529 return getInput(btnB, false, true);
9022 }
9023 14158857 bool DrunkcEx1btn()
9024 {
9025 14158857 return getInput(btnEx1, false, true);
9026 }
9027 14157489 bool DrunkcEx2btn()
9028 {
9029 14157489 return getInput(btnEx2, false, true);
9030 }
9031 bool DrunkcSbtn()
9032 {
9033 return getInput(btnS, false, true);
9034 }
9035 bool DrunkcMbtn()
9036 {
9037 return getInput(btnM, false, true);
9038 }
9039 bool DrunkcLbtn()
9040 {
9041 return getInput(btnL, false, true);
9042 }
9043 bool DrunkcRbtn()
9044 {
9045 return getInput(btnR, false, true);
9046 }
9047 bool DrunkcPbtn()
9048 {
9049 return getInput(btnP, false, true);
9050 }
9051
9052 bool DrunkrUp()
9053 {
9054 return getInput(btnUp, true, true);
9055 }
9056 bool DrunkrDown()
9057 {
9058 return getInput(btnDown, true, true);
9059 }
9060 bool DrunkrLeft()
9061 {
9062 return getInput(btnLeft, true, true);
9063 }
9064 bool DrunkrRight()
9065 {
9066 return getInput(btnRight, true, true);
9067 }
9068 11830634 bool DrunkrAbtn()
9069 {
9070 11830634 return getInput(btnA, true, true);
9071 }
9072 11859166 bool DrunkrBbtn()
9073 {
9074 11859166 return getInput(btnB, true, true);
9075 }
9076 502081 bool DrunkrEx1btn()
9077 {
9078 502081 return getInput(btnEx1, true, true);
9079 }
9080 501902 bool DrunkrEx2btn()
9081 {
9082 501902 return getInput(btnEx2, true, true);
9083 }
9084 bool DrunkrEx3btn()
9085 {
9086 return getInput(btnEx3, true, true);
9087 }
9088 bool DrunkrEx4btn()
9089 {
9090 return getInput(btnEx4, true, true);
9091 }
9092 bool DrunkrSbtn()
9093 {
9094 return getInput(btnS, true, true);
9095 }
9096 bool DrunkrMbtn()
9097 {
9098 return getInput(btnM, true, true);
9099 }
9100 12896561 bool DrunkrLbtn()
9101 {
9102 12896561 return getInput(btnL, true, true);
9103 }
9104 12891256 bool DrunkrRbtn()
9105 {
9106 12891256 return getInput(btnR, true, true);
9107 }
9108 bool DrunkrPbtn()
9109 {
9110 return getInput(btnP, true, true);
9111 }
9112
9113 18803 void eat_buttons()
9114 {
9115 18803 getInput(btnA, true, false, true);
9116 18803 getInput(btnB, true, false, true);
9117 18803 getInput(btnS, true, false, true);
9118 18803 getInput(btnM, true, false, true);
9119 18803 getInput(btnL, true, false, true);
9120 18803 getInput(btnR, true, false, true);
9121 18803 getInput(btnP, true, false, true);
9122 18803 getInput(btnEx1, true, false, true);
9123 18803 getInput(btnEx2, true, false, true);
9124 18803 getInput(btnEx3, true, false, true);
9125 18803 getInput(btnEx4, true, false, true);
9126 18803 }
9127
9128 // Is true for the _first frame_ of a key press.
9129 // But! it is possible that a script manually sets the value of KeyPress,
9130 // in which case it will be restored to the "true" value based on `key_current_frame`
9131 // and `key_previous_frame` on the next frame.
9132 55 bool zc_readkey(int32_t k, bool ignoreDisable)
9133 {
9134
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(ignoreDisable) return KeyPress[k];
9135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 switch(k)
9136 {
9137 case KEY_F7:
9138 case KEY_F8:
9139 case KEY_F9:
9140 return KeyPress[k];
9141
9142 default:
9143
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 10 times.
55 return KeyPress[k] && !disabledKeys[k];
9144 }
9145 55 }
9146
9147 // Is true for _every frame_ a key is held down.
9148 // But! it is possible that a script manually sets the value of KeyInput,
9149 // in which case it will be restored to the "true" value based on `key_current_frame`
9150 // on the next frame.
9151 bool zc_getkey(int32_t k, bool ignoreDisable)
9152 {
9153 if(ignoreDisable) return KeyInput[k];
9154 switch(k)
9155 {
9156 case KEY_F7:
9157 case KEY_F8:
9158 case KEY_F9:
9159 return KeyInput[k];
9160
9161 default:
9162 return KeyInput[k] && !disabledKeys[k];
9163 }
9164 }
9165
9166 // Reads (and then clears) the current frame key state directly.
9167 // Scripts can also modify `key_current_frame`.
9168 916 bool zc_readrawkey(int32_t k, bool ignoreDisable)
9169 {
9170
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 914 times.
916 if(zc_getrawkey(k, ignoreDisable))
9171 {
9172 2 _key[k]=key[k]=key_current_frame[k]=0;
9173 2 return true;
9174 }
9175 914 _key[k]=key[k]=key_current_frame[k]=0;
9176 914 return false;
9177 916 }
9178
9179 // Reads the current frame key state directly.
9180 // Scripts can also modify `key_current_frame`.
9181 124413661 bool zc_getrawkey(int32_t k, bool ignoreDisable)
9182 {
9183
2/2
✓ Branch 0 taken 106095208 times.
✓ Branch 1 taken 18318453 times.
124413661 if(ignoreDisable) return key_current_frame[k];
9184
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18318453 times.
18318453 switch(k)
9185 {
9186 case KEY_F7:
9187 case KEY_F8:
9188 case KEY_F9:
9189 return key_current_frame[k];
9190
9191 default:
9192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18318453 times.
18318453 return key_current_frame[k] && !disabledKeys[k];
9193 }
9194 124413661 }
9195
9196 // Only used for a handful of keys, like tilde and Function keys.
9197 // This state is never read within the game.
9198 // It exists so that all keyboard input still functions during replay,
9199 // without inadvertently doing things like toggling throttling if the player
9200 // presses ~
9201 bool zc_get_system_key(int32_t k)
9202 {
9203 return key_system[k];
9204 }
9205
9206 // True for the _first_ frame of a key press.
9207 164865087 bool zc_read_system_key(int32_t k)
9208 {
9209 164865087 return key_system_press[k];
9210 }
9211
9212 2326429561 bool is_system_key(int32_t k)
9213 {
9214
2/2
✓ Branch 0 taken 2161564474 times.
✓ Branch 1 taken 164865087 times.
2326429561 switch (k)
9215 {
9216 case KEY_BACKQUOTE:
9217 case KEY_CLOSEBRACE:
9218 case KEY_END:
9219 case KEY_HOME:
9220 case KEY_OPENBRACE:
9221 case KEY_PGDN:
9222 case KEY_PGUP:
9223 case KEY_TAB:
9224 case KEY_TILDE:
9225 164865087 return true;
9226 }
9227 2161564474 return is_Fkey(k);
9228 2326429561 }
9229
9230 18318343 void update_system_keys()
9231 {
9232
2/2
✓ Branch 0 taken 2326429561 times.
✓ Branch 1 taken 18318343 times.
2344747904 for (int32_t q = 0; q < 127; ++q)
9233 {
9234
2/2
✓ Branch 0 taken 384685203 times.
✓ Branch 1 taken 1941744358 times.
2326429561 if (!is_system_key(q))
9235 1941744358 continue;
9236
9237 384685203 key_system[q] = key[q];
9238
1/2
✓ Branch 0 taken 384685203 times.
✗ Branch 1 not taken.
384685203 key_system_press[q] = key_system[q] && !key_system_previous[q];
9239 384685203 key_system_previous[q] = key_system[q];
9240 384685203 }
9241 18318343 }
9242
9243 19584855 void update_keys()
9244 {
9245
2/2
✓ Branch 0 taken 2487276585 times.
✓ Branch 1 taken 19584855 times.
2506861440 for (int32_t q = 0; q < 127; ++q)
9246 {
9247 // When replaying, replay.cpp takes care of updating `key_current_frame`.
9248
2/2
✓ Branch 0 taken 2487263885 times.
✓ Branch 1 taken 12700 times.
2487276585 if (!replay_is_replaying())
9249 12700 key_current_frame[q] = key[q];
9250
9251
2/2
✓ Branch 0 taken 2468183033 times.
✓ Branch 1 taken 19093552 times.
2487276585 KeyPress[q] = key_current_frame[q] && !key_previous_frame[q];
9252 2487276585 KeyInput[q] = key_current_frame[q];
9253 2487276585 key_previous_frame[q] = key_current_frame[q];
9254 2487276585 }
9255 19584855 }
9256
9257 bool zc_disablekey(int32_t k, bool val)
9258 {
9259 switch(k)
9260 {
9261 case KEY_F7:
9262 case KEY_F8:
9263 case KEY_F9:
9264 return false;
9265
9266 default:
9267 disabledKeys[k] = val;
9268 return true;
9269 }
9270 }
9271
9272 void zc_putpixel(int32_t layer, int32_t x, int32_t y, int32_t cset, int32_t color, int32_t timer)
9273 {
9274 timer=timer;
9275 particles.add(new particle(zfix(x), zfix(y), layer, cset, color));
9276 }
9277